PluralKit/PluralKit.Web/Startup.cs

55 lines
1.7 KiB
C#
Raw Normal View History

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)
{
var config = Configuration.GetSection("PluralKit").Get<CoreConfig>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services
.AddSingleton<IDbConnection, NpgsqlConnection>(_ => new NpgsqlConnection(config.Database))
.AddSingleton<SystemStore>()
.AddSingleton<MemberStore>()
.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<IDbConnection>();
conn.Open();
await Schema.CreateTables(conn);
}
}
}