AuthorBuddy/Program.cs

44 lines
1.4 KiB
C#
Raw Normal View History

2026-05-14 12:31:35 +02:00
using AuthorBuddy.Web.Components;
using AuthorBuddy.Web.Data;
using AuthorBuddy.Web.Models;
using AuthorBuddy.Web.Services;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddSingleton<OllamaSettings>();
builder.Services.AddSingleton<IOllamaService, OllamaService>();
builder.Services.AddSingleton<IFileScannerService, FileScannerService>();
2026-05-16 16:13:35 +02:00
builder.Services.AddSingleton<ISettingsService, SettingsService>();
builder.Services.AddScoped<IThemeService, ThemeService>();
2026-05-14 12:31:35 +02:00
builder.Services.AddSingleton<IProjectService, ProjectService>();
builder.Services.AddDbContextFactory<AppDbContext>(options =>
options.UseSqlite(Constants.SQLiteConnection));
var app = builder.Build();
2026-05-17 07:27:18 +02:00
AppDbContext.SetupVecExtension(Constants.SQLiteConnection);
await using var db = await app.Services.GetRequiredService<IDbContextFactory<AppDbContext>>().CreateDbContextAsync();
await db.Database.MigrateAsync();
var settingsInit = app.Services.GetRequiredService<ISettingsService>();
await settingsInit.InitializeAsync();
2026-05-14 12:31:35 +02:00
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
}
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();