|
85 | 85 | builder.Services.AddScoped<MerchantRuntime>(); |
86 | 86 | builder.Services.AddSingleton<IMerchantRuntimeFactory, MerchantRuntimeFactory>(); |
87 | 87 | builder.Services.AddSingleton<MerchantMetrics>(); |
88 | | - builder.Services.AddSingleton<Func<String, String>>( |
89 | | - new Func<String, String>(configSetting => |
90 | | - { |
91 | | - return configSetting switch |
92 | | - { |
93 | | - "SecurityService" => "https://localhost:5001", |
94 | | - "TransactionProcessorACL" => "http://localhost:5003", |
95 | | - "TransactionProcessorApi" => "http://localhost:5002", |
96 | | - "EstateReportingApi" => "http://localhost:5004", |
97 | | - "TestHost" => "http://localhost:9000", |
98 | | - _ => string.Empty, |
99 | | - }; |
100 | | - })); |
| 88 | + //builder.Services.AddSingleton<Func<String, String>>( |
| 89 | + // configSetting => |
| 90 | + // { |
| 91 | + // return configSetting switch |
| 92 | + // { |
| 93 | + // "SecurityService" => "https://localhost:5001", |
| 94 | + // "TransactionProcessorACL" => "http://localhost:5003", |
| 95 | + // "TransactionProcessorApi" => "http://localhost:5002", |
| 96 | + // "TestHost" => "http://localhost:9000", |
| 97 | + // _ => string.Empty, |
| 98 | + // }; |
| 99 | + // }); |
| 100 | + |
| 101 | + // Replace the existing AddSingleton<Func<String, String>>(...) registration with this: |
| 102 | + builder.Services.AddSingleton<Func<string, string>>(sp => |
| 103 | + { |
| 104 | + // Resolve IConfiguration from the DI container |
| 105 | + var config = sp.GetRequiredService<IConfiguration>().GetSection("ApiConfiguration"); |
| 106 | + |
| 107 | + // Return a small resolver that looks up keys in the ApiConfiguration section (case-insensitive) |
| 108 | + return (string configSetting) => |
| 109 | + { |
| 110 | + if (string.IsNullOrWhiteSpace(configSetting)) |
| 111 | + return string.Empty; |
| 112 | + |
| 113 | + // Section indexer is case-sensitive by default, so use GetChildren() to perform case-insensitive lookup |
| 114 | + var child = config.GetChildren() |
| 115 | + .FirstOrDefault(c => string.Equals(c.Key, configSetting, StringComparison.OrdinalIgnoreCase)); |
| 116 | + return child?.Value ?? string.Empty; |
| 117 | + }; |
| 118 | + }); |
101 | 119 | // Health checks |
102 | 120 | builder.Services.AddHealthChecks(); |
103 | 121 |
|
|
0 commit comments