using System.Data; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Npgsql; namespace PluralKit.Web { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { DatabaseUtils.Init(); var config = Configuration.GetSection("PluralKit").Get(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services .AddScoped(_ => new NpgsqlConnection(config.Database)) .AddTransient() .AddTransient() .AddSingleton(config); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } //app.UseHttpsRedirection(); app.UseMvc(); var conn = app.ApplicationServices.GetRequiredService(); conn.Open(); await Schema.CreateTables(conn); } } }