refactor: consolidate service registration into AddMoneyMapCore extension
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MoneyMap.Data;
|
||||
using MoneyMap.Services;
|
||||
using MoneyMap.Services.AITools;
|
||||
|
||||
namespace MoneyMap.Core;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddMoneyMapCore(
|
||||
this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<MoneyMapContext>(options =>
|
||||
options.UseSqlServer(configuration.GetConnectionString("MoneyMapDb")));
|
||||
|
||||
services.AddMemoryCache();
|
||||
|
||||
// Core transaction and import services
|
||||
services.AddScoped<ITransactionImporter, TransactionImporter>();
|
||||
services.AddScoped<ICardResolver, CardResolver>();
|
||||
services.AddScoped<ITransactionCategorizer, TransactionCategorizer>();
|
||||
services.AddScoped<ITransactionService, TransactionService>();
|
||||
services.AddScoped<ITransactionStatisticsService, TransactionStatisticsService>();
|
||||
|
||||
// Entity management services
|
||||
services.AddScoped<IAccountService, AccountService>();
|
||||
services.AddScoped<ICardService, CardService>();
|
||||
services.AddScoped<IMerchantService, MerchantService>();
|
||||
services.AddScoped<IBudgetService, BudgetService>();
|
||||
|
||||
// Receipt services
|
||||
services.AddScoped<IReceiptMatchingService, ReceiptMatchingService>();
|
||||
services.AddScoped<IReceiptManager, ReceiptManager>();
|
||||
services.AddScoped<IReceiptAutoMapper, ReceiptAutoMapper>();
|
||||
services.AddScoped<IPdfToImageConverter, PdfToImageConverter>();
|
||||
|
||||
// Reference data and dashboard
|
||||
services.AddScoped<IReferenceDataService, ReferenceDataService>();
|
||||
services.AddScoped<IDashboardService, DashboardService>();
|
||||
services.AddScoped<IDashboardStatsCalculator, DashboardStatsCalculator>();
|
||||
services.AddScoped<ITopCategoriesProvider, TopCategoriesProvider>();
|
||||
services.AddScoped<IRecentTransactionsProvider, RecentTransactionsProvider>();
|
||||
services.AddScoped<ISpendTrendsProvider, SpendTrendsProvider>();
|
||||
|
||||
// AI services
|
||||
services.AddScoped<IAIToolExecutor, AIToolExecutor>();
|
||||
services.AddScoped<IFinancialAuditService, FinancialAuditService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
+5
-48
@@ -1,8 +1,6 @@
|
||||
using System.Globalization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoneyMap.Data;
|
||||
using MoneyMap.Core;
|
||||
using MoneyMap.Services;
|
||||
using MoneyMap.Services.AITools;
|
||||
using MoneyMap.WebApp.Services;
|
||||
|
||||
// Set default culture to en-US for currency formatting ($)
|
||||
@@ -12,11 +10,8 @@ CultureInfo.DefaultThreadCurrentUICulture = culture;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddDbContext<MoneyMapContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("MoneyMapDb")));
|
||||
|
||||
// Add memory cache for services like TransactionCategorizer
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.AddMoneyMapCore(builder.Configuration);
|
||||
builder.Services.AddSingleton<IReceiptStorageOptions, WebReceiptStorageOptions>();
|
||||
|
||||
// Add session support
|
||||
builder.Services.AddDistributedMemoryCache();
|
||||
@@ -25,47 +20,13 @@ builder.Services.AddSession(options =>
|
||||
options.IdleTimeout = TimeSpan.FromMinutes(30);
|
||||
options.Cookie.HttpOnly = true;
|
||||
options.Cookie.IsEssential = true;
|
||||
options.IOTimeout = TimeSpan.FromMinutes(5); // Increase timeout for large data
|
||||
options.IOTimeout = TimeSpan.FromMinutes(5);
|
||||
});
|
||||
|
||||
// Use session-based TempData provider to avoid cookie size limits
|
||||
builder.Services.AddRazorPages()
|
||||
.AddSessionStateTempDataProvider();
|
||||
|
||||
// Core transaction and import services
|
||||
builder.Services.AddScoped<ITransactionImporter, TransactionImporter>();
|
||||
builder.Services.AddScoped<ICardResolver, CardResolver>();
|
||||
builder.Services.AddScoped<ITransactionCategorizer, TransactionCategorizer>();
|
||||
builder.Services.AddScoped<ITransactionService, TransactionService>();
|
||||
builder.Services.AddScoped<ITransactionStatisticsService, TransactionStatisticsService>();
|
||||
|
||||
// Entity management services
|
||||
builder.Services.AddScoped<IAccountService, AccountService>();
|
||||
builder.Services.AddScoped<ICardService, CardService>();
|
||||
builder.Services.AddScoped<IMerchantService, MerchantService>();
|
||||
builder.Services.AddScoped<IBudgetService, BudgetService>();
|
||||
|
||||
// Receipt services
|
||||
builder.Services.AddScoped<IReceiptMatchingService, ReceiptMatchingService>();
|
||||
|
||||
// Reference data services
|
||||
builder.Services.AddScoped<IReferenceDataService, ReferenceDataService>();
|
||||
|
||||
// Dashboard services
|
||||
builder.Services.AddScoped<IDashboardService, DashboardService>();
|
||||
builder.Services.AddScoped<IDashboardStatsCalculator, DashboardStatsCalculator>();
|
||||
builder.Services.AddScoped<ITopCategoriesProvider, TopCategoriesProvider>();
|
||||
builder.Services.AddScoped<IRecentTransactionsProvider, RecentTransactionsProvider>();
|
||||
builder.Services.AddScoped<ISpendTrendsProvider, SpendTrendsProvider>();
|
||||
|
||||
// Receipt storage configuration
|
||||
builder.Services.AddSingleton<IReceiptStorageOptions, WebReceiptStorageOptions>();
|
||||
|
||||
// Receipt services
|
||||
builder.Services.AddScoped<IReceiptManager, ReceiptManager>();
|
||||
builder.Services.AddScoped<IReceiptAutoMapper, ReceiptAutoMapper>();
|
||||
builder.Services.AddScoped<IPdfToImageConverter, PdfToImageConverter>();
|
||||
|
||||
// Receipt parse queue and background worker
|
||||
builder.Services.AddSingleton<IReceiptParseQueue, ReceiptParseQueue>();
|
||||
builder.Services.AddHostedService<ReceiptParseWorkerService>();
|
||||
@@ -76,18 +37,14 @@ builder.Services.AddHttpClient<ClaudeVisionClient>();
|
||||
builder.Services.AddHttpClient<OllamaVisionClient>();
|
||||
builder.Services.AddHttpClient<LlamaCppVisionClient>();
|
||||
builder.Services.AddScoped<IAIVisionClientResolver, AIVisionClientResolver>();
|
||||
builder.Services.AddScoped<IAIToolExecutor, AIToolExecutor>();
|
||||
builder.Services.AddScoped<IReceiptParser, AIReceiptParser>();
|
||||
|
||||
// AI categorization service
|
||||
builder.Services.AddHttpClient<ITransactionAICategorizer, TransactionAICategorizer>();
|
||||
|
||||
// Model warmup service - preloads the configured AI model on startup
|
||||
// Model warmup service
|
||||
builder.Services.AddHostedService<ModelWarmupService>();
|
||||
|
||||
// Financial audit API service
|
||||
builder.Services.AddScoped<IFinancialAuditService, FinancialAuditService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Seed default category mappings on startup
|
||||
|
||||
Reference in New Issue
Block a user