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?
At run time, the ConfigureServices method is called before the Configure method. This is so that you can register your custom service with the IoC container which you may use in the Configure method.
The ConfigureServices method is a public method on your Startup class that takes an IServiceCollection instance as a parameter and optionally returns an IServiceProvider . The ConfigureServices method is called before Configure .
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 -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With