chore: init project
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using InboxIntel.Application.Abstractions;
|
||||
using InboxIntel.Domain.Enums;
|
||||
using InboxIntel.Infrastructure.Ai;
|
||||
using InboxIntel.Infrastructure.Analytics;
|
||||
using InboxIntel.Infrastructure.Cleanup;
|
||||
using InboxIntel.Infrastructure.Configuration;
|
||||
using InboxIntel.Infrastructure.Export;
|
||||
using InboxIntel.Infrastructure.Gmail;
|
||||
using InboxIntel.Infrastructure.Persistence;
|
||||
using InboxIntel.Infrastructure.Search;
|
||||
using InboxIntel.Infrastructure.Security;
|
||||
using InboxIntel.Infrastructure.Sync;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace InboxIntel.Infrastructure;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
// EF Core / PostgreSQL
|
||||
services.AddDbContext<AppDbContext>(opt =>
|
||||
opt.UseNpgsql(config.GetConnectionString("Postgres"),
|
||||
npg => npg.MigrationsAssembly(typeof(AppDbContext).Assembly.FullName)));
|
||||
services.AddScoped<IAppDbContext>(sp => sp.GetRequiredService<AppDbContext>());
|
||||
|
||||
// Options
|
||||
services.Configure<GoogleOAuthOptions>(config.GetSection(GoogleOAuthOptions.SectionName));
|
||||
services.Configure<GmailSyncOptions>(config.GetSection(GmailSyncOptions.SectionName));
|
||||
services.Configure<AiOptions>(config.GetSection(AiOptions.SectionName));
|
||||
|
||||
// Security
|
||||
services.AddSingleton<ITokenProtector, DataProtectionTokenProtector>();
|
||||
|
||||
// Gmail
|
||||
services.AddScoped<GmailClientFactory>();
|
||||
services.AddScoped<IGmailService, GmailApiService>();
|
||||
|
||||
// Core services
|
||||
services.AddScoped<ISyncService, SyncService>();
|
||||
services.AddScoped<IAnalyticsService, AnalyticsService>();
|
||||
services.AddScoped<ISearchService, SearchService>();
|
||||
services.AddScoped<ICleanupService, CleanupService>();
|
||||
services.AddScoped<IUnsubscribeService, UnsubscribeService>();
|
||||
services.AddScoped<IExportService, ExportService>();
|
||||
|
||||
// HTTP clients
|
||||
services.AddHttpClient("unsubscribe", c => c.Timeout = TimeSpan.FromSeconds(15));
|
||||
services.AddHttpClient("ollama");
|
||||
services.AddHttpClient("openai");
|
||||
|
||||
// AI provider selected by configured mode.
|
||||
var aiMode = config.GetSection(AiOptions.SectionName).GetValue<AiProviderMode>("Mode");
|
||||
switch (aiMode)
|
||||
{
|
||||
case AiProviderMode.LocalOllama: services.AddScoped<IAiProvider, OllamaProvider>(); break;
|
||||
case AiProviderMode.CloudOpenAi: services.AddScoped<IAiProvider, OpenAiProvider>(); break;
|
||||
default: services.AddScoped<IAiProvider, NullAiProvider>(); break;
|
||||
}
|
||||
services.AddScoped<IAiService, AiService>();
|
||||
|
||||
// Background worker (daily incremental sync + aggregate refresh)
|
||||
services.AddHostedService<GmailSyncWorker>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user