How to define multiple Owin partial run classes and make them run your code

I am working on an MVC application that will be equipped with a "plugin" architecture.

Basically there will be a main "host" project that will dynamically load other projects at runtime.

We want to move all ASP.NET related stuff into a separate plugin project.

The main host project already contains an Owin startup class which has some logic that it must execute. However, we also need to create an Owin launch class in the Identity plugin project so that we can call ConfigureAuth ().

How can i do this?

MvcPluginHost.Web Startup.cs

[assembly: OwinStartupAttribute(typeof(MvcPluginHost.Web.Startup))]
namespace MvcPluginHost.Web
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}

      

MvcPluginHost.Plugins.IdentityPlugin Startup.cs

[assembly: OwinStartupAttribute(typeof(MvcPluginHost.Plugins.IdentityPlugin.Startup))]
namespace MvcPluginHost.Plugins.IdentityPlugin
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

      

+3


source to share


1 answer


Partial classes are not meant to do this, the first thing that comes to mind is to request the required assemblies for some interface and call a common method for all of them.



var type = typeof(IMyInterface);
var types = AppDomain.CurrentDomain.GetAssemblies()
    .SelectMany(s => s.GetTypes())
    .Where(p => type.IsAssignableFrom(p));

foreach(var implementation in types)
{
    var obj = (IMyInterface)Activator.CreateInstance(implementation);
    obj.RunPlugin() //Interface method you're trying to implement in partials
}

      

+4


source







All Articles