AuthorBuddy/Program.cs

69 lines
2.2 KiB
C#
Raw Normal View History

2026-05-14 12:31:35 +02:00
using AuthorBuddy.Web.Components;
using AuthorBuddy.Web.Models;
using AuthorBuddy.Web.Services;
2026-05-20 06:12:54 +02:00
using LiteDB;
2026-05-21 11:04:42 +02:00
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Components.Authorization;
2026-05-25 06:38:16 +02:00
using Microsoft.Extensions.FileProviders;
2026-05-14 12:31:35 +02:00
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
2026-05-20 06:12:54 +02:00
var dbPath = Path.Combine(AppContext.BaseDirectory, Constants.DbFile);
builder.Services.AddSingleton<ILiteDatabase>(new LiteDatabase($"Filename={dbPath};Connection=direct"));
2026-05-14 12:31:35 +02:00
builder.Services.AddSingleton<OllamaSettings>();
builder.Services.AddSingleton<IOllamaService, OllamaService>();
builder.Services.AddSingleton<IFileScannerService, FileScannerService>();
2026-05-25 06:38:16 +02:00
builder.Services.AddScoped<ISettingsService, SettingsService>();
2026-05-16 16:13:35 +02:00
builder.Services.AddScoped<IThemeService, ThemeService>();
2026-05-14 12:31:35 +02:00
builder.Services.AddSingleton<IProjectService, ProjectService>();
2026-05-20 06:12:54 +02:00
builder.Services.AddSingleton<IRagService, RagService>();
builder.Services.AddSingleton<IWikipediaService, WikipediaService>();
2026-05-21 11:04:42 +02:00
builder.Services.AddScoped<IAuthService, AuthService>();
2026-05-25 06:38:16 +02:00
builder.Services.AddScoped<ILocalizationService, LocalizationService>();
2026-05-21 11:04:42 +02:00
builder.Services.AddScoped<CustomAuthStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(sp =>
sp.GetRequiredService<CustomAuthStateProvider>());
builder.Services.AddAuthorizationCore();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/login";
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromDays(30);
});
2026-05-14 12:31:35 +02:00
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
}
2026-05-21 11:04:42 +02:00
2026-05-14 12:31:35 +02:00
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseAntiforgery();
2026-05-25 06:38:16 +02:00
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(app.Environment.ContentRootPath, "Assets")),
RequestPath = "/Assets"
});
2026-05-14 12:31:35 +02:00
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();
2026-05-21 11:04:42 +02:00
public partial class Program
{
public const bool DebugAutoLogin = true;
}