From 62fa1d5c4c681f044573e8bbea0ff37717a8831f Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 20 Apr 2026 18:20:23 -0400 Subject: [PATCH] refactor: consolidate service registration into AddMoneyMapCore extension Co-Authored-By: Claude Opus 4.6 --- MoneyMap.Core/ServiceCollectionExtensions.cs | 53 ++++++++++++++++++++ MoneyMap/Program.cs | 53 ++------------------ 2 files changed, 58 insertions(+), 48 deletions(-) create mode 100644 MoneyMap.Core/ServiceCollectionExtensions.cs diff --git a/MoneyMap.Core/ServiceCollectionExtensions.cs b/MoneyMap.Core/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..29239c2 --- /dev/null +++ b/MoneyMap.Core/ServiceCollectionExtensions.cs @@ -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(options => + options.UseSqlServer(configuration.GetConnectionString("MoneyMapDb"))); + + services.AddMemoryCache(); + + // Core transaction and import services + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + // Entity management services + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + // Receipt services + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + // Reference data and dashboard + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + // AI services + services.AddScoped(); + services.AddScoped(); + + return services; + } +} diff --git a/MoneyMap/Program.cs b/MoneyMap/Program.cs index a30893a..6c61c38 100644 --- a/MoneyMap/Program.cs +++ b/MoneyMap/Program.cs @@ -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(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(); // 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(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); - -// Entity management services -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); - -// Receipt services -builder.Services.AddScoped(); - -// Reference data services -builder.Services.AddScoped(); - -// Dashboard services -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); - -// Receipt storage configuration -builder.Services.AddSingleton(); - -// Receipt services -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); - // Receipt parse queue and background worker builder.Services.AddSingleton(); builder.Services.AddHostedService(); @@ -76,18 +37,14 @@ builder.Services.AddHttpClient(); builder.Services.AddHttpClient(); builder.Services.AddHttpClient(); builder.Services.AddScoped(); -builder.Services.AddScoped(); builder.Services.AddScoped(); // AI categorization service builder.Services.AddHttpClient(); -// Model warmup service - preloads the configured AI model on startup +// Model warmup service builder.Services.AddHostedService(); -// Financial audit API service -builder.Services.AddScoped(); - var app = builder.Build(); // Seed default category mappings on startup