+14
-1
@@ -1,10 +1,12 @@
|
||||
using Azure.Identity;
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Api.Data;
|
||||
using Api.Services;
|
||||
using Api.Services.Contracts;
|
||||
using Api.Settings;
|
||||
using Serilog;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
DotNetEnv.Env.Load();
|
||||
|
||||
@@ -64,8 +66,12 @@ try
|
||||
builder.Services.Configure<AiSettings>(builder.Configuration.GetSection("Ai"));
|
||||
builder.Services.Configure<InternalApiSettings>(builder.Configuration.GetSection("InternalApi"));
|
||||
|
||||
builder.Services.AddDbContext<RagDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("RagDb")
|
||||
?? throw new InvalidOperationException("Connection string 'RagDb' is missing.")));
|
||||
|
||||
builder.Services.AddHttpClient<RawAiClient>();
|
||||
builder.Services.AddSingleton<IRagRepository, SqlRagRepository>();
|
||||
builder.Services.AddScoped<IRagRepository, EfRagRepository>();
|
||||
builder.Services.AddScoped<IAiClient, CachedAiClient>();
|
||||
builder.Services.AddSingleton<ITextExtractor, TextExtractor>();
|
||||
builder.Services.AddSingleton<ITextChunker, TextChunker>();
|
||||
@@ -159,6 +165,13 @@ try
|
||||
app.MapControllers();
|
||||
app.MapGet("/health", () => Results.Ok(new { status = "ok", service = "rag-api", version = appVersion, timeUtc = DateTimeOffset.UtcNow }));
|
||||
|
||||
Log.Information("Running EfCore DbMigrations if any");
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<RagDbContext>();
|
||||
db.Database.Migrate();
|
||||
}
|
||||
|
||||
Log.Information("{Service} startup complete", "rag-api");
|
||||
app.Run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user