57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
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)
|
|
{
|
|
InitUtils.Init();
|
|
|
|
var config = Configuration.GetSection("PluralKit").Get<CoreConfig>();
|
|
|
|
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
|
|
|
services
|
|
.AddScoped<IDbConnection, NpgsqlConnection>(_ => new NpgsqlConnection(config.Database))
|
|
.AddTransient<SystemStore>()
|
|
.AddTransient<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);
|
|
}
|
|
}
|
|
} |