首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为DbContext配置OpenIddict

为DbContext配置OpenIddict
EN

Stack Overflow用户
提问于 2016-05-04 11:17:16
回答 1查看 2K关注 0票数 1

在我的OpenIddict核心应用程序中,我使用.NET进行JWT令牌身份验证。我已经跟踪了本教程,但现在收到了以下错误:

代码语言:javascript
复制
InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider...

Startup.cs中的My Startup.cs方法

代码语言:javascript
复制
        public void ConfigureServices(IServiceCollection services)
    {
        var builder = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json");
        Configuration = builder.Build();

        services.AddEntityFrameworkSqlServer()
             .AddDbContext<MyDbContext>(options =>
                 options.UseSqlServer(Configuration["Data:MyDbContext:ConnectionString"]));

        services.AddIdentity<ApplicationUser, ApplicationRole>()
            .AddEntityFrameworkStores<MyDbContext>()
            .AddDefaultTokenProviders()
            .AddOpenIddictCore<Application>(config => config.UseEntityFramework());

        services.AddMvc();

        // for seeding the database with the demo user details
        //services.AddTransient<IDatabaseInitializer, DatabaseInitializer>();
        services.AddScoped<OpenIddictManager<ApplicationUser, Application>, CustomOpenIddictManager>();
    }

不知道该怎么做,因为我不能在使用DbContext时添加AddIdentity

我的连接字符串很好,添加OpenIddict之前一切都正常。

更新这里是我的appsettings.json文件:

代码语言:javascript
复制
    {
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Verbose",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "Data": {
    "DefaultConnection": {
      "ConnectionString": "my connection string"
    },
    "SaleboatContext": {
      "ConnectionString": "my connection string"
    }
  }
}

我的DbContext:

代码语言:javascript
复制
public class ApplicationUser : IdentityUser { }

public partial class MyDbContext : IdentityDbContext<ApplicationUser>
{

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-09 15:29:09

由于EntityFramework Core RC2中的设计更改,您现在需要手动地流DbContextOptions或在OnModelCreating中直接配置连接字符串。

尝试将此构造函数添加到DB上下文(应该从OpenIddictContext派生):

代码语言:javascript
复制
public partial class MyDbContext : OpenIddictContext<ApplicationUser> {
    public MyDbContext(DbContextOptions options)
        : base(options) {
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37026273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档