示例#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())
            {
                app.UseDeveloperExceptionPage();
            }

            // migrate
            try
            {
                var builder          = new DbContextOptionsBuilder <EosContext>();
                var connectionString = _configuration.GetConnectionString("common");
                // builder.UseSqlServer(connectionString);
                builder.UseNpgsql(connectionString, builder =>
                {
                    Console.WriteLine("Use Postgres Database Provider");
                    builder.MigrationsAssembly("Eos.Data.EF.Postgres");
                });
                using var context = new EosContext(builder.Options);
                var migrations = context.Database.GetPendingMigrations().ToList();
                if (migrations.Any())
                {
                    context.Database.Migrate();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            app.UseRouting();
            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

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