The pattern JaliyaUdagedara shared above takes advantage of an extension method. This is a very typically pattern going back to the beginning of Core. Your code is not well designed for Core start up. Plus it expects a role and usermanger service instance.
I recommend going through any of the getting tutorials in the official documentation as they all cover seeding data. The official documentation also illustrates how to instantiate a service within the seed extension method. Follow the same pattern to get the role and usermanager services.
Seed the database
Initialize DB with test data
This is the pattern I use.
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddDbContext<RazorPagesMovieContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("RazorPagesMovieContext")));
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
SeedData.Initialize(services);
}
....
public static class SeedData
{
public static void Initialize(IServiceProvider serviceProvider)
{
using (var context = new RazorPagesMovieContext(
serviceProvider.GetRequiredService<
DbContextOptions<RazorPagesMovieContext>>()))
{