| | | 1 | | using Microsoft.Extensions.DependencyInjection; |
| | | 2 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 3 | | using Microsoft.Extensions.Logging; |
| | | 4 | | using Orchestrator.Infrastructure.Factories; |
| | | 5 | | |
| | | 6 | | namespace Orchestrator.Infrastructure; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Extension methods for registering Orchestrator services in dependency injection. |
| | | 10 | | /// </summary> |
| | | 11 | | public static class ServiceRegistrationExtensions |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Registers all shared infrastructure services (factories, logging). |
| | | 15 | | /// </summary> |
| | | 16 | | /// <remarks> |
| | | 17 | | /// This method is idempotent - calling it multiple times has no additional effect. |
| | | 18 | | /// </remarks> |
| | | 19 | | public static IServiceCollection AddOrchestratorInfrastructure(this IServiceCollection services) |
| | | 20 | | { |
| | | 21 | | // Add logging (idempotent via TryAdd internally) |
| | 0 | 22 | | services.AddLogging(builder => |
| | 0 | 23 | | { |
| | 0 | 24 | | builder.SetMinimumLevel(LogLevel.Information); |
| | 0 | 25 | | }); |
| | | 26 | | |
| | | 27 | | // Add memory cache for Kicktipp client |
| | 0 | 28 | | services.AddMemoryCache(); |
| | | 29 | | |
| | | 30 | | // Add HTTP client factory for Kicktipp |
| | 0 | 31 | | services.AddHttpClient(); |
| | | 32 | | |
| | | 33 | | // Register factories (idempotent) |
| | 0 | 34 | | services.TryAddSingleton<IFirebaseServiceFactory, FirebaseServiceFactory>(); |
| | 0 | 35 | | services.TryAddSingleton<IKicktippClientFactory, KicktippClientFactory>(); |
| | 0 | 36 | | services.TryAddSingleton<IOpenAiServiceFactory, OpenAiServiceFactory>(); |
| | 0 | 37 | | services.TryAddSingleton<IContextProviderFactory, ContextProviderFactory>(); |
| | | 38 | | |
| | 0 | 39 | | return services; |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Registers services specific to the ListKpiCommand. |
| | | 44 | | /// </summary> |
| | | 45 | | /// <remarks> |
| | | 46 | | /// This method is idempotent and ensures infrastructure is registered. |
| | | 47 | | /// </remarks> |
| | | 48 | | public static IServiceCollection AddListKpiCommandServices(this IServiceCollection services) |
| | | 49 | | { |
| | 0 | 50 | | services.AddOrchestratorInfrastructure(); |
| | | 51 | | |
| | | 52 | | // ListKpiCommand only needs Firebase factory (uses IKpiRepository) |
| | | 53 | | // No command-specific keyed services needed - factory pattern handles runtime config |
| | | 54 | | |
| | 0 | 55 | | return services; |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Registers services specific to the UploadKpiCommand. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <remarks> |
| | | 62 | | /// This method is idempotent and ensures infrastructure is registered. |
| | | 63 | | /// </remarks> |
| | | 64 | | public static IServiceCollection AddUploadKpiCommandServices(this IServiceCollection services) |
| | | 65 | | { |
| | 0 | 66 | | services.AddOrchestratorInfrastructure(); |
| | | 67 | | |
| | | 68 | | // UploadKpiCommand only needs Firebase factory (uses IKpiRepository) |
| | | 69 | | // No command-specific keyed services needed - factory pattern handles runtime config |
| | | 70 | | |
| | 0 | 71 | | return services; |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Registers services specific to the CostCommand. |
| | | 76 | | /// </summary> |
| | | 77 | | /// <remarks> |
| | | 78 | | /// This method is idempotent and ensures infrastructure is registered. |
| | | 79 | | /// </remarks> |
| | | 80 | | public static IServiceCollection AddCostCommandServices(this IServiceCollection services) |
| | | 81 | | { |
| | 0 | 82 | | services.AddOrchestratorInfrastructure(); |
| | | 83 | | |
| | | 84 | | // CostCommand needs Firebase factory (uses IPredictionRepository, FirestoreDb) |
| | | 85 | | // No command-specific keyed services needed - factory pattern handles runtime config |
| | | 86 | | |
| | 0 | 87 | | return services; |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// Registers services specific to the MatchdayCommand. |
| | | 92 | | /// </summary> |
| | | 93 | | /// <remarks> |
| | | 94 | | /// This method is idempotent and ensures infrastructure is registered. |
| | | 95 | | /// </remarks> |
| | | 96 | | public static IServiceCollection AddMatchdayCommandServices(this IServiceCollection services) |
| | | 97 | | { |
| | 0 | 98 | | services.AddOrchestratorInfrastructure(); |
| | | 99 | | |
| | | 100 | | // MatchdayCommand needs all factories: |
| | | 101 | | // - Firebase (IPredictionRepository, IContextRepository) |
| | | 102 | | // - Kicktipp (IKicktippClient) |
| | | 103 | | // - OpenAI (IPredictionService, ITokenUsageTracker) |
| | | 104 | | // Factory pattern handles runtime config based on settings |
| | | 105 | | |
| | 0 | 106 | | return services; |
| | | 107 | | } |
| | | 108 | | |
| | | 109 | | /// <summary> |
| | | 110 | | /// Registers services specific to the BonusCommand. |
| | | 111 | | /// </summary> |
| | | 112 | | /// <remarks> |
| | | 113 | | /// This method is idempotent and ensures infrastructure is registered. |
| | | 114 | | /// </remarks> |
| | | 115 | | public static IServiceCollection AddBonusCommandServices(this IServiceCollection services) |
| | | 116 | | { |
| | 0 | 117 | | services.AddOrchestratorInfrastructure(); |
| | | 118 | | |
| | | 119 | | // BonusCommand needs all factories: |
| | | 120 | | // - Firebase (IPredictionRepository, IKpiRepository) |
| | | 121 | | // - Kicktipp (IKicktippClient) |
| | | 122 | | // - OpenAI (IPredictionService, ITokenUsageTracker) |
| | | 123 | | |
| | 0 | 124 | | return services; |
| | | 125 | | } |
| | | 126 | | |
| | | 127 | | /// <summary> |
| | | 128 | | /// Registers services specific to the VerifyMatchdayCommand. |
| | | 129 | | /// </summary> |
| | | 130 | | public static IServiceCollection AddVerifyMatchdayCommandServices(this IServiceCollection services) |
| | | 131 | | { |
| | 0 | 132 | | services.AddOrchestratorInfrastructure(); |
| | | 133 | | |
| | | 134 | | // VerifyMatchdayCommand needs: |
| | | 135 | | // - Firebase (IPredictionRepository, IContextRepository) |
| | | 136 | | // - Kicktipp (IKicktippClient) |
| | | 137 | | |
| | 0 | 138 | | return services; |
| | | 139 | | } |
| | | 140 | | |
| | | 141 | | /// <summary> |
| | | 142 | | /// Registers services specific to the VerifyBonusCommand. |
| | | 143 | | /// </summary> |
| | | 144 | | public static IServiceCollection AddVerifyBonusCommandServices(this IServiceCollection services) |
| | | 145 | | { |
| | 0 | 146 | | services.AddOrchestratorInfrastructure(); |
| | | 147 | | |
| | | 148 | | // VerifyBonusCommand needs: |
| | | 149 | | // - Firebase (IPredictionRepository, IKpiRepository) |
| | | 150 | | // - Kicktipp (IKicktippClient) |
| | | 151 | | |
| | 0 | 152 | | return services; |
| | | 153 | | } |
| | | 154 | | |
| | | 155 | | /// <summary> |
| | | 156 | | /// Registers services specific to the CollectContextKicktippCommand. |
| | | 157 | | /// </summary> |
| | | 158 | | public static IServiceCollection AddCollectContextKicktippCommandServices(this IServiceCollection services) |
| | | 159 | | { |
| | 0 | 160 | | services.AddOrchestratorInfrastructure(); |
| | | 161 | | |
| | | 162 | | // CollectContextKicktippCommand needs: |
| | | 163 | | // - Firebase (IContextRepository) |
| | | 164 | | // - Kicktipp (IKicktippClient) |
| | | 165 | | |
| | 0 | 166 | | return services; |
| | | 167 | | } |
| | | 168 | | |
| | | 169 | | /// <summary> |
| | | 170 | | /// Registers services specific to the ContextChangesCommand. |
| | | 171 | | /// </summary> |
| | | 172 | | public static IServiceCollection AddContextChangesCommandServices(this IServiceCollection services) |
| | | 173 | | { |
| | 0 | 174 | | services.AddOrchestratorInfrastructure(); |
| | | 175 | | |
| | | 176 | | // ContextChangesCommand only needs Firebase (IContextRepository) |
| | | 177 | | |
| | 0 | 178 | | return services; |
| | | 179 | | } |
| | | 180 | | |
| | | 181 | | /// <summary> |
| | | 182 | | /// Registers services specific to the UploadTransfersCommand. |
| | | 183 | | /// </summary> |
| | | 184 | | public static IServiceCollection AddUploadTransfersCommandServices(this IServiceCollection services) |
| | | 185 | | { |
| | 0 | 186 | | services.AddOrchestratorInfrastructure(); |
| | | 187 | | |
| | | 188 | | // UploadTransfersCommand only needs Firebase (IContextRepository) |
| | | 189 | | |
| | 0 | 190 | | return services; |
| | | 191 | | } |
| | | 192 | | |
| | | 193 | | /// <summary> |
| | | 194 | | /// Registers services specific to the AnalyzeMatchDetailedCommand. |
| | | 195 | | /// </summary> |
| | | 196 | | public static IServiceCollection AddAnalyzeMatchDetailedCommandServices(this IServiceCollection services) |
| | | 197 | | { |
| | 0 | 198 | | services.AddOrchestratorInfrastructure(); |
| | | 199 | | |
| | | 200 | | // AnalyzeMatchDetailedCommand needs: |
| | | 201 | | // - Firebase (IContextRepository) |
| | | 202 | | // - OpenAI (IPredictionService, ITokenUsageTracker) |
| | | 203 | | |
| | 0 | 204 | | return services; |
| | | 205 | | } |
| | | 206 | | |
| | | 207 | | /// <summary> |
| | | 208 | | /// Registers services specific to the AnalyzeMatchComparisonCommand. |
| | | 209 | | /// </summary> |
| | | 210 | | public static IServiceCollection AddAnalyzeMatchComparisonCommandServices(this IServiceCollection services) |
| | | 211 | | { |
| | 0 | 212 | | services.AddOrchestratorInfrastructure(); |
| | | 213 | | |
| | | 214 | | // AnalyzeMatchComparisonCommand needs: |
| | | 215 | | // - Firebase (IContextRepository) |
| | | 216 | | // - OpenAI (IPredictionService, ITokenUsageTracker) |
| | | 217 | | |
| | 0 | 218 | | return services; |
| | | 219 | | } |
| | | 220 | | |
| | | 221 | | /// <summary> |
| | | 222 | | /// Registers all command services. Useful for production setup. |
| | | 223 | | /// </summary> |
| | | 224 | | public static IServiceCollection AddAllCommandServices(this IServiceCollection services) |
| | | 225 | | { |
| | | 226 | | // Infrastructure is added by each command method, but we call it first for clarity |
| | 0 | 227 | | services.AddOrchestratorInfrastructure(); |
| | | 228 | | |
| | | 229 | | // Register all command-specific services |
| | 0 | 230 | | services.AddListKpiCommandServices(); |
| | 0 | 231 | | services.AddUploadKpiCommandServices(); |
| | 0 | 232 | | services.AddCostCommandServices(); |
| | 0 | 233 | | services.AddMatchdayCommandServices(); |
| | 0 | 234 | | services.AddBonusCommandServices(); |
| | 0 | 235 | | services.AddVerifyMatchdayCommandServices(); |
| | 0 | 236 | | services.AddVerifyBonusCommandServices(); |
| | 0 | 237 | | services.AddCollectContextKicktippCommandServices(); |
| | 0 | 238 | | services.AddContextChangesCommandServices(); |
| | 0 | 239 | | services.AddUploadTransfersCommandServices(); |
| | 0 | 240 | | services.AddAnalyzeMatchDetailedCommandServices(); |
| | 0 | 241 | | services.AddAnalyzeMatchComparisonCommandServices(); |
| | | 242 | | |
| | 0 | 243 | | return services; |
| | | 244 | | } |
| | | 245 | | } |