The type or namespace name 'OpenIddictDbContext<,,>' could not be found

廉价感情. 提交于 2019-12-04 10:47:15

Starting with beta2, OpenIddict no longer comes with a dedicated DbContext you can subclass, as this pattern - inherited from ASP.NET Core Identity - proved to be rather impractical.

Instead, you're now encouraged to directly inherit from IdentityDbContext and register the entity sets needed by OpenIddict by calling options.UseOpenIddict() from ConfigureServices:

project.json:

"dependencies": {
  "OpenIddict": "1.0.0-*",
  "OpenIddict.EntityFrameworkCore": "1.0.0-*",
  "OpenIddict.Mvc": "1.0.0-*"
}

Startup:

services.AddDbContext<ApplicationDbContext>(options =>
{
    // Configure the context to use Microsoft SQL Server.
    options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"]);

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

// Register the OpenIddict services.
services.AddOpenIddict(options =>
{
    // Register the Entity Framework stores.
    options.AddEntityFrameworkCoreStores<ApplicationDbContext>();
});

ApplicationDbContext:

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

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

        // 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);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!