I am writing a ASP.NET Classic WebAPI application. I have implemented the OWIN StartUp class, and the Caonfiguration method is executed, however, the ConfigureServices method does not get executed. I know this works for DotNetCore.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(ClassicWebApi.Startup))]
namespace ClassicWebApi
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
//CODE IS NOT EXECUTED
}
public void Configuration(IAppBuilder app)
{
//CODE IS EXECUTED
}
}
}
Is this only a feature of DotNetCore or do I need to include another library in the set up?
I'd like to use the dependency injection. Specifically the AddDbContext and AddScoped
Build-in dependency injection is only available in ASP.NET Core. You will need to use third party IoC container such as -
You can use Microsoft.Extensions.DependencyInjection with non-Core projects. You'll simply call ConfigureServices(IServiceCollection services) from Global.asax Application_Start method.
来源:https://stackoverflow.com/questions/45222923/asp-net-classic-owin-startup-configureservices-not-called