示例#1
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataSeeder seeder)
        {
            using (IServiceScope scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                DataContext dbContext = scope.ServiceProvider.GetRequiredService <DataContext>();
                dbContext.Database.Migrate();
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                seeder.Init();
            }

            //app.UseHttpsRedirection();

            app.UseStaticFiles();

            app.UseRouting();

            app.UseSwagger();

            const string docsPrefix = "api/docs";

            app.UseSwaggerUI(c =>
            {
                c.RoutePrefix = docsPrefix;
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "FireBird API");
                c.InjectStylesheet("/docs/custom.css");
            });

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapGet("/", async(e) =>
                {
                    string[] fullName = typeof(Startup).Assembly.FullName.Split(',');

                    await e.Response.WriteAsync(JsonSerializer.Serialize(new
                    {
                        Status      = true,
                        Environment = env.EnvironmentName,
                        Name        = fullName[0],
                        Version     = fullName[1].Remove(0, 9),
                        Docs        = $"{e.Request.Scheme}://{e.Request.Host}/{docsPrefix}"
                    }));
                });
            });
        }
示例#2
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            // Find the service layer
            using (var scope = host.Services.CreateScope())
            {
                // get instance of dbcontext in service layer
                IServiceProvider services = scope.ServiceProvider;
                TodoDbContext    context  = services.GetRequiredService <TodoDbContext>();

                //Seed data
                DataSeeder.Init(services);
            }

            host.Run();
        }
示例#3
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataSeeder seeder)
        {
            using (IServiceScope serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                DataContext context = serviceScope.ServiceProvider.GetRequiredService <DataContext>();
                context.Database.Migrate();
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                seeder.Init();
            }

            app.UseRouting();

            app.UseAuthorization();

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