What is CreatePerOwinContext replacement in AspNetCore?

こ雲淡風輕ζ 提交于 2019-12-01 22:03:09

问题


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:


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);
    }
}


来源:https://stackoverflow.com/questions/38810310/what-is-createperowincontext-replacement-in-aspnetcore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!