Esempio n. 1
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())
            {
                using (var scope = app.ApplicationServices.CreateScope())
                {
                    PetShop2020DBContext context = scope.ServiceProvider.GetService <PetShop2020DBContext>();
                    context.Database.EnsureDeleted(); // only in dev mode. never in prod mode or the whole database will be lost.
                    context.Database.EnsureCreated();
                    IDBInitializer DbInit = scope.ServiceProvider.GetService <IDBInitializer>();
                    DbInit.Seed(context);
                }

                app.UseDeveloperExceptionPage();
            }
            if (env.IsProduction())
            {
                using (var scope = app.ApplicationServices.CreateScope())
                {
                    PetShop2020DBContext context = scope.ServiceProvider.GetService <PetShop2020DBContext>();
                    context.Database.EnsureCreated();
                    IDBInitializer dbInitializer = scope.ServiceProvider.GetService <IDBInitializer>();
                    dbInitializer.Seed(context);
                }
            }
            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "Pet Shop API");
                options.RoutePrefix = "";
            });

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCors();

            app.UseAuthentication();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>

                             { endpoints.MapControllers(); });
        }
Esempio n. 2
0
 public UserRepository(PetShop2020DBContext context)
 {
     _context = context;
 }