1

在 owin 中,我为映射的应用程序构建器配置了不同的服务,如下所示:

using (WebApp.Start("http://localhost:8001", app =>
{
    app.Map("/context1", appBuilder => {
        appBuilder.UseWebApi();
        appBuilder.ConfigureIoc();
    });
    app.Map("/context2", appBuilder =>{
        appBuilder.UseNancy();
        appBuilder.ConfigureIoc();

    });
}))
{
    Console.ReadLine();
}

在 asp.net 核心中,我需要为每个映射的应用程序构建器配置服务,但所有注册的服务都应用于所有映射的应用程序构建器。我将为每个 appBuilder 配置服务。

public void ConfigureServices(IServiceCollection services)
{
    services.AddScoped<IFooService, DefaultFooService>();
    services.AddMvc();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.Map(new PathString("/context1"), appBuilder  =>
    {
        // appBuilder.AddMvc();
        // appBuilder.ConfigureIoc();
    });
    app.Map(new PathString("/context2"), appBuilder  =>
    {
        // appBuilder.UseNancy();
        // appBuilder.ConfigureIoc();
    });
}
4

0 回答 0