What is CreatePerOwinContext replacement in AspNet

2020-04-10 00:18发布

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.

1条回答
何必那么认真
2楼-- · 2020-04-10 00:31

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);
    }
}
查看更多
登录 后发表回答