What is the CreatePerOwinContext
replacement, if any, in AspNetCore?
I'm trying to migrate the Asp.Net Identity samples to AspNet Core, and finding that the legacy? package that provides the CreatePerOwinContext
extension method is not compatible with Asp.Net Core framework.
After some digging...it seems that CreatePerOwinContext
was primarily part of a dependency injection mechanism.
Microsoft.AspNetCore 1.0.0 supports dependency injection as a first-class citizen.
https://docs.asp.net/en/latest/fundamentals/dependency-injection.html
Extensions are available for most of the common Identity services that are required. For example, below is a comparison of the CreatePerOwinContext
compared to the IServiceCollection
IServiceCollection (AspNetCore 1.0.0)
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(config.GetConnectionString("DefaultConnection")));
}
}
CreatePerOwinContext (obsolete)
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
}
}