Ejemplo n.º 1
0
        private static void SeedData(IHost host)
        {
            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;
            var context  = services.GetRequiredService <ApplicationDBContext>();

            MovieContextSeed.SeedMovieDataAsync(context);
        }
 private static void SeedDataBase(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services      = scope.ServiceProvider;
         var moviesContext = services.GetRequiredService <MoviesAPIContext>();
         MovieContextSeed.SeedAsync(moviesContext);
     }
 }
Ejemplo n.º 3
0
 private static async Task CreateAndSeedDb(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services      = scope.ServiceProvider;
         var loggerFactory = services.GetRequiredService <ILoggerFactory>();
         try
         {
             var moviesContext = services.GetRequiredService <MovieContext>();
             await MovieContextSeed.SeedAsync(moviesContext, loggerFactory);
         }
         catch (Exception ex)
         {
             var logger = loggerFactory.CreateLogger <Program>();
             logger.LogError($"Exception Occured in API: {ex.Message}");
         }
     }
 }
Ejemplo n.º 4
0
        private static void CreateAndSeedDatabase(IHost host)
        {
            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();

                try
                {
                    var aspnetRunContext = services.GetRequiredService <MovieDbContext>();
                    MovieContextSeed.SeedAsync(aspnetRunContext, loggerFactory).Wait();
                }
                catch (Exception exception)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(exception, "An error occurred seeding the DB.");
                }
            }
        }