// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataSeeder seeder)
        {
            seeder.Seed().GetAwaiter().GetResult();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
            }

            var localizationOptions = app.ApplicationServices.GetService <IOptions <RequestLocalizationOptions> >();

            app.UseRequestLocalization(localizationOptions.Value);

            app.UseCors("Default");
            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var serviceScope = host.Services.CreateScope())
            {
                var serviceProvider = serviceScope.ServiceProvider;

                try
                {
                    var databaseContext = serviceProvider.GetRequiredService <DatabaseContext>();
                    var userManager     = serviceProvider.GetRequiredService <UserManager <AppUser> >();

                    databaseContext.Database.Migrate();
                    DataSeeder.Seed(databaseContext, userManager).Wait();
                }
                catch (Exception exception)
                {
                    Log.Error(
                        $"An error occurred while seeding the database " +
                        $"{exception.Message} {exception.StackTrace} " +
                        $"{exception.InnerException} {exception.Source}"
                        );
                }
            }

            host.Run();
        }
Exemple #3
0
        public static void SeedDataContext(this IApplicationBuilder application)
        {
            using (var serviceScope = application.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <DataContext>();

                context.Database.EnsureCreated();

                var databaseSeeder = new DataSeeder(context);
                if (!context.Contacts.Any())
                {
                    databaseSeeder.SeedContacts();
                }
            }
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var dbContext = services.GetRequiredService <AppDbContext>();
                dbContext.Database.Migrate();
                DataSeeder.SeedData(dbContext).Wait();
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error occured during migration");
            }

            host.Run();
        }
Exemple #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
            }

            app.UseHttpsRedirection();

            app.UseRouting();
            app.UseCors();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            DataSeeder.Seed(app);
        }