I did not have access to DI.
this explanation is incorrect, you can inject UserManager in another assembly read more.
Just create a service for seeding your data for example:
public interface IInitializationService
{
void Seed();
}
public class InitializationService : IInitializationService
{
private readonly UserManager<ApplicationUser> _userManager;
public InitializationService(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}
public void Seed()
{
// more code
}
}
Register service in Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddTransient<IInitializationService, InitializationService>();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// more code ...
var scopeFactory = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>();
using (var scope = scopeFactory.CreateScope())
{
var identityDbInitialize = scope.ServiceProvider.GetService<IInitializationService>();
identityDbInitialize.Seed();
}
// more code ...
}