什么是AspNetCore中的CreatePerOwinContext替代品? [英] What is CreatePerOwinContext replacement in AspNetCore?

查看:123
本文介绍了什么是AspNetCore中的CreatePerOwinContext替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AspNetCore中的CreatePerOwinContext替代品(如果有)是什么?

What is the CreatePerOwinContext replacement, if any, in AspNetCore?

我正在尝试将Asp.Net Identity样本迁移到AspNet Core,并发现遗留问题?提供CreatePerOwinContext扩展方法的程序包与Asp.Net Core框架不兼容.

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.

推荐答案

经过一番挖掘……看来CreatePerOwinContext主要是依赖注入机制的一部分.

After some digging...it seems that CreatePerOwinContext was primarily part of a dependency injection mechanism.

Microsoft.AspNetCore 1.0.0支持作为一等公民的依赖项注入.

Microsoft.AspNetCore 1.0.0 supports dependency injection as a first-class citizen.

https://docs.asp.net/en/latest/basics/dependency-injection.html

扩展可用于所需的大多数常见身份服务.例如,下面是CreatePerOwinContextIServiceCollection

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(已淘汰)

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.CreatePerOwinContext(ApplicationDbContext.Create);
    }
}

这篇关于什么是AspNetCore中的CreatePerOwinContext替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆