OWIN cannot run multiple apps in isolation using webapp.start

て烟熏妆下的殇ゞ 提交于 2019-12-05 01:20:33

问题


When I try and start two apps on different url's, I get problems with attribute routing middleware. If I have two similar routes in seperate apps but with different http methods web.api seems find only one of the methods.

Microsoft.Owin.Hosting.WebApp.Start<Admin.Startup>("http://localhost:1000");
Microsoft.Owin.Hosting.WebApp.Start<Startup>("http://localhost:1001");

How can I isolate both apps so that attribute routing don't conflict?


回答1:


Based on your last comment, an example below to filter out the assemblies:

config.Services.Replace(typeof(IAssembliesResolver), new CustomAssembliesResolver());

public class CustomAssembliesResolver : DefaultAssembliesResolver
{
    public override ICollection<Assembly> GetAssemblies()
    {
        ICollection<Assembly> defaultProbedAssemblies = base.GetAssemblies();

        //TODO: filter out the assemblies that you do not want to be probed

        return defaultProbedAssemblies;
    }
}



回答2:


I had the exact same issue and @KiranChalla's answer got me going down the right path (thanks!). The problem was indeed with the assembly scanning going deeper than I wanted it to. For me I always wanted the scan to only include the assembly where the "current" Startup is defined, as that is the Web API project where all relevant controllers live. I created a resolver that always returns just one assembly:

public class SingleAssemblyResolver : IAssembliesResolver
{
    private readonly Assembly _ass;

    public SingleAssemblyResolver(Assembly ass) {
        _ass = ass;
    }

    public ICollection<Assembly> GetAssemblies() {
        return new[] { _ass };
    }
}

And told it which assembly ("this" one) when registering it in each Startup:

config.Services.Replace(typeof(IAssembliesResolver),
    new SingleAssemblyResolver(this.GetType().Assembly));


来源:https://stackoverflow.com/questions/20884646/owin-cannot-run-multiple-apps-in-isolation-using-webapp-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!