ASP.NET Classic OWIN StartUp ConfigureServices not called

Viewed 7449

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?

2 Answers

You can use Microsoft.Extensions.DependencyInjection with non-Core projects. You'll simply call ConfigureServices(IServiceCollection services) from Global.asax Application_Start method.

Related