是否可以在 运行 时间使用两个不同的 Owin 启动文件?

Is it possible to use two different Owin startup file at run time?

我正在使用带有 MEF framework 的 Asp.net MVC 5 应用程序,以允许我将 MVC 应用程序设计为主应用程序中的插件。

我需要我的一个插件需要有自己的 OwinStart class,运行 位于主 Owin class 之后 class我的主要应用程序。

换句话说 main.dllStartup class 总是需要先 运行,然后 plugin.dllStartup class 需要 运行 秒。

是否可以拥有 2 个自己的创业公司 classes?

来自 Docs about detecting StartUp class

The OwinStartup attribute overrides the naming convention. You can also specify a friendly name with this attribute, however, using a friendly name requires you to also use the appSetting element in the configuration file.

所以我尝试像这样添加一个友好的名称

[assembly: OwinStartup("pluginStartup", typeof(plugin.Startup))]

在配置文件中添加了以下内容

<appSettings>  
  <add key="owin:appStartup" value="Main.Startup, Main" />
</appSettings>

但这不归档我的 Plugin.Startup 它只 运行s Main.Startup.

有没有办法 运行 两个不同的 Startup classes?

https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-startup-class-detection

似乎无法 运行 多个启动文件。

但是,我使用反射来完成工作。基本上,我在所有程序集中搜索任何 class 实现 IAppConfiguration 接口,然后在该实例上调用 Configuration

这是我的做法。

我创建了一个界面

public interface IAppConfiguration
{
    void Configuration(IAppBuilder app);
}

然后在我的 main.dll 中我将以下代码添加到我的 Startup class.

    public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);
        ConfigurePlugins(app);
    }

    private static void ConfigurePlugins(IAppBuilder app)
    {
        try
        {
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                var startups = assembly.GetTypes().Where(x => x.IsClass && typeof(IAppConfiguration ).IsAssignableFrom(x)).ToList();

                foreach (Type startup in startups)
                {
                    var config = (IAppConfiguration )Activator.CreateInstance(startup);

                    config.Configuration(app);
                }
            }
        }
        catch
        {

        }
    }