Entity framework core 具有DB上下文工厂的标识存储
在我的ASP.NET Core 5.0项目中,我更改了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
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
{
...
}