I am using RavenDb.Identity as my identity provider for a .Net 6 WebApi project. I am trying to seed user data and as part of that I need to access UserManager and RoleManager - like this
private readonly ILogger<DatabaseSeeder> _logger;
private readonly UserManager<ApplicationUser> _userManager;
private readonly RoleManager<ApplicationRole> _roleManager;
public DatabaseSeeder( UserManager<ApplicationUser> userManager, RoleManager<ApplicationRole> roleManager,
ILogger<DatabaseSeeder> logger)
{
_userManager = userManager;
_roleManager = roleManager;
_logger = logger;
}
UserManager and RoleManager are supposed to be added to the DI in Program.cs from the following code
builder.Services.AddRavenDbDocStore()
.AddRavenDbAsyncSession()
.AddIdentity<ApplicationUser, ApplicationRole>(options =>
{
options.Password.RequiredLength = 8;
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.User.RequireUniqueEmail = true;
})
.AddRavenDbIdentityStores<ApplicationUser, ApplicationRole>();
But for some reason they are not getting added and I end up with the error message:
Cannot resolve 'Infrastructure.Seed.Identity.IDatabaseSeeder' from root provider because it requires scoped service 'Microsoft.AspNetCore.Identity.UserManager`1[Domain.Entities.Identity.ApplicationUser]'.
FYI: This is .Net 6 WebAPI project using WebApplicationBuilder.
Can you please help?