48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using Phenix.Services;
|
|
|
|
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
|
{
|
|
Args = args,
|
|
WebRootPath = "static",
|
|
});
|
|
|
|
builder.Services
|
|
.AddControllersWithViews()
|
|
.AddRazorOptions(o =>
|
|
{
|
|
o.ViewLocationFormats.Clear();
|
|
o.ViewLocationFormats.Add("/Views/{1}/{0}.cshtml");
|
|
o.ViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
|
|
o.ViewLocationFormats.Add("/Views/{0}.cshtml");
|
|
});
|
|
|
|
builder.Services.AddSingleton<IGameService>(sp =>
|
|
{
|
|
var config = sp.GetRequiredService<IConfiguration>();
|
|
var connStr = config.GetConnectionString("Default")
|
|
?? "Data Source=phenix.db";
|
|
var provider = config["DatabaseProvider"] ?? "Sqlite";
|
|
|
|
IGameService svc = provider.ToLowerInvariant() switch
|
|
{
|
|
"postgres" or "postgresql" => new PostgresGameService(connStr),
|
|
_ => new SqliteGameService(connStr),
|
|
};
|
|
svc.Init().GetAwaiter().GetResult();
|
|
return svc;
|
|
});
|
|
|
|
builder.Services.AddSingleton(sp =>
|
|
{
|
|
var key = sp.GetRequiredService<IConfiguration>()["SessionKey"] ?? "dev-only";
|
|
return new LoginService(key);
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|