示例#1
0
        //dodavanje podataka prilikom pokretanja aplikacije
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context     = services.GetRequiredService <ApplicationDbContext>();
                    var userManager = services.GetRequiredService <UserManager <Korisnik> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.Administratori(userManager, roleManager);

                    await ContextSeed.Predavaci(userManager, roleManager);

                    //await ContextSeed.Polaznik(userManager,roleManager);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "Došlo je do pogreške prilikom postavljanja DB-a.");
                }
            }
            host.Run();
        }