Я использую OpenIddict для аутентификации маркера JWT в моем приложении .NET Core. Я следовал this tutorial, но теперь я получаю следующее сообщение об ошибке:Конфигурировать DbContext для OpenIddict
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...
Мой ConfigureServices
метод в Startup.cs
:
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.
UPDATE Вот мой appsettings.json
файл:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Verbose",
"System": "Information",
"Microsoft": "Information"
}
},
"Data": {
"DefaultConnection": {
"ConnectionString": "my connection string"
},
"SaleboatContext": {
"ConnectionString": "my connection string"
}
}
}
Мой DbContext:
public class ApplicationUser : IdentityUser { }
public partial class MyDbContext : IdentityDbContext<ApplicationUser>
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
Не могли бы вы поделиться своим контекстом DB? Я хотел бы убедиться, что строка соединения правильно протестирована до EntityFramework. – Pinpoint
Моя строка подключения не в моем dbcontext, это в моем appsettings.json –
Если ваша строка подключения настроена, это не очень важно. Я просто хочу убедиться, что ваш контекст имеет правильный конструктор, чтобы разрешить внешнюю конфигурацию. – Pinpoint