How to configure services in Owin startup class in ASP.NET framework

Viewed 262
public void Configuration(IAppBuilder app) 
{
    // code is executed 
}

public void ConfigureServices(IServiceCollection services) 
{
    // code is not executed  
}
2 Answers

Based on OWIN Startup Class Detection, you have to add the NuGet package Microsoft.Owin.Host.SystemWeb and then reference a OWIN Startup class from VisualStudio template, then in the following code you can access OWIN:

[assembly: OwinStartup("ProductionConfiguration", typeof(StartupDemo.ProductionStartup2))]

namespace StartupDemo
{
    public class ProductionStartup
    {
        public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                string t = DateTime.Now.Millisecond.ToString();
                return context.Response.WriteAsync(t + " Production OWIN App");
            });
        }
    }
    public class ProductionStartup2
    {
        public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                string t = DateTime.Now.Millisecond.ToString();
                return context.Response.WriteAsync(t + " 2nd Production OWIN App");
            });
        }
    }
}
Related