代码之家  ›  专栏  ›  技术社区  ›  Igor

以另一种方式将OpenIddict实体注册到DbContext中

  •  1
  • Igor  · 技术社区  · 8 年前

    是否有其他方法来注册所需的实体集 OpenIddict 在一个 DbContext options.UseOpenIddict(); 在里面 services.AddDbContext<OpenIdDictDbContext>(options => {...}) .

    DbContexts ,我想与大家分享 DbContextOptions .

    在里面Net Core 2,如果可以使用非泛型 DbContextOptions 数据库上下文 或者你必须有非泛型 DbContextOptions<T> 对于所有人 . 因此,如果可能的话,我希望采用第一种方法。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Kévin Chalet    8 年前

    您可以直接从注册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.DependencyInjection 使用和项目引用 OpenIddict.EntityFrameworkCore