Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework core 具有DB上下文工厂的标识存储_Entity Framework Core_.net 5_Asp.net Core Identity_Asp.net Core 5.0_Asp.net5 - Fatal编程技术网

Entity framework core 具有DB上下文工厂的标识存储

Entity framework core 具有DB上下文工厂的标识存储,entity-framework-core,.net-5,asp.net-core-identity,asp.net-core-5.0,asp.net5,Entity Framework Core,.net 5,Asp.net Core Identity,Asp.net Core 5.0,Asp.net5,在我的ASP.NET Core 5.0项目中,我更改了 services.AddDbContext<SelfProgressDbContext>(...); 是否有办法使默认标识存储通过其新工厂解析DB上下文?在ConfigureServices中,尝试使用addScope()方法注册DBContext,并使用提供程序从服务获取工厂。然后,将实例返回给提供者。代码如下所示: services.AddDbContextFactory<ApplicationDbC

在我的ASP.NET Core 5.0项目中,我更改了

services.AddDbContext<SelfProgressDbContext>(...);

是否有办法使默认标识存储通过其新工厂解析DB上下文?

在ConfigureServices中,尝试使用addScope()方法注册DBContext,并使用提供程序从服务获取工厂。然后,将实例返回给提供者。代码如下所示:

        services.AddDbContextFactory<ApplicationDbContext>(options =>
        {
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
            options.EnableSensitiveDataLogging();
        });

        services.AddScoped<ApplicationDbContext>(p => p.GetRequiredService<IDbContextFactory<ApplicationDbContext>>().CreateDbContext());

您可以使用
services.AddDbContext(options=>options.UseSqlServer(connectionString))以及。。。你知道还有别的办法吗?可能是自定义IdentityBuilder扩展?
services
    .AddIdentity<User, IdentityRole<Guid>>(...)
    .AddEntityFrameworkStores<SelfProgressDbContext>()
    .AddDefaultTokenProviders()
        services.AddDbContextFactory<ApplicationDbContext>(options =>
        {
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
            options.EnableSensitiveDataLogging();
        });

        services.AddScoped<ApplicationDbContext>(p => p.GetRequiredService<IDbContextFactory<ApplicationDbContext>>().CreateDbContext());
public class ApplicationDbContext : IdentityDbContext
{
     ...
}