1

是否有另一种方法可以将所需的实体集注册OpenIddict到一个DbContextexcept 调用 options.UseOpenIddict();services.AddDbContext<OpenIdDictDbContext>(options => {...})

我有这种方法的麻烦,因为我有更多DbContexts,我想分享DbContextOptions

在 .Net Core 2 中,如果您可以DbContextOptions对 all使用 nongeneric,DbContexts或者您必须DbContextOptions<T>对 all使用 nongeneric DbContexts。所以,如果可能的话,我想要第一种方法。

4

1 回答 1

1

您可以直接从以下位置注册 OpenIddict 实体OnModelCreating

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext(DbContextOptions options)
        : base(options) { }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        // Register the entity sets needed by OpenIddict.
        // Note: use the generic overload if you need
        // to replace the default OpenIddict entities.
        builder.UseOpenIddict();

        // Customize the ASP.NET Identity model and override the defaults if needed.
        // For example, you can rename the ASP.NET Identity table names and more.
        // Add your customizations after calling base.OnModelCreating(builder);
    }
}

如果您没有看到扩展名,请确保您有Microsoft.Extensions.DependencyInjectionusing 并且您的项目引用了OpenIddict.EntityFrameworkCore.

于 2017-09-20T18:24:10.500 回答