Esempio n. 1
0
        private static void SeedDatabase(IHost host)
        {
            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;
            var context  = services.GetRequiredService <UsersWebApiContext>();

            UsersContextSeed.SeedAsync(context);
        }
Esempio n. 2
0
        public void PrepareDatabase(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            try
            {
                using (var scope = app.ApplicationServices.CreateScope())
                {
                    var settings = scope.ServiceProvider.GetRequiredService <IOptions <UserSettings> >();

                    var context          = new MongoContext(settings);
                    var usersContextSeed = new UsersContextSeed(context);
                    usersContextSeed.SeedAsync(app, loggerFactory).Wait();
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Esempio n. 3
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.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

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

            UsersContextSeed.SeedAsync(app).Wait();
        }
Esempio n. 4
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseCors("CorsPolicy");
            app.UseMvcWithDefaultRoute();
            app.UseSwagger()
            .UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Sfeir puppy API V1");
                c.OAuthClientId("usersswaggerui");
                c.OAuthAppName("Users Swagger UI");
            });

            // Seed Data
            UsersContextSeed.SeedAsync(app, loggerFactory).Wait();
        }