【发布时间】:2020-01-26 11:18:40
【问题描述】:
我正在尝试基于 http://docs.identityserver.io/en/latest/quickstarts/8_aspnet_identity.html 并使用来自 https://github.com/IdentityServer/IdentityServer4/tree/master/samples/Quickstarts/8_AspNetIdentity 的代码作为我的模板来启动 Identity Server 实例,但我无法获取种子数据。
根据示例应用程序,我有我的 program.cs 和 startup.cs。当我打电话时
var userMgr = scope.ServiceProvider.GetRequiredService<UserManager<IdentityUser>>();
来自SeedData.EnsureSeedData 方法,该方法紧随其后
var services = new ServiceCollection();
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString));
services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
using var serviceProvider = services.BuildServiceProvider();
using var scope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope();
var context = scope.ServiceProvider.GetService<ApplicationDbContext>();
context.Database.Migrate();
var userMgr = scope.ServiceProvider.GetRequiredService<UserManager<IdentityUser>>();
我收到以下错误。
Unable to resolve service for type 'Microsoft.Extensions.Logging.ILogger`1[Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]]' while attempting to activate 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]'.
如何为ILogger<UserManager<IdentityUser>>> 注册服务?
我觉得我遗漏了一些明显的东西,但看不到它是什么。
【问题讨论】:
标签: c# asp.net-core .net-core asp.net-core-mvc identityserver4