Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions TransactionProcessing.MerchantPos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,37 @@
builder.Services.AddScoped<MerchantRuntime>();
builder.Services.AddSingleton<IMerchantRuntimeFactory, MerchantRuntimeFactory>();
builder.Services.AddSingleton<MerchantMetrics>();
builder.Services.AddSingleton<Func<String, String>>(
new Func<String, String>(configSetting =>
{
return configSetting switch
{
"SecurityService" => "https://localhost:5001",
"TransactionProcessorACL" => "http://localhost:5003",
"TransactionProcessorApi" => "http://localhost:5002",
"EstateReportingApi" => "http://localhost:5004",
"TestHost" => "http://localhost:9000",
_ => string.Empty,
};
}));
//builder.Services.AddSingleton<Func<String, String>>(
// configSetting =>
// {

Check notice on line 90 in TransactionProcessing.MerchantPos/Program.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TransactionProcessing.MerchantPos/Program.cs#L90

Remove this commented out code.
// return configSetting switch
// {
// "SecurityService" => "https://localhost:5001",
// "TransactionProcessorACL" => "http://localhost:5003",
// "TransactionProcessorApi" => "http://localhost:5002",
// "TestHost" => "http://localhost:9000",
// _ => string.Empty,
// };
// });

// Replace the existing AddSingleton<Func<String, String>>(...) registration with this:
builder.Services.AddSingleton<Func<string, string>>(sp =>
{
// Resolve IConfiguration from the DI container
var config = sp.GetRequiredService<IConfiguration>().GetSection("ApiConfiguration");

// Return a small resolver that looks up keys in the ApiConfiguration section (case-insensitive)
return (string configSetting) =>
{
if (string.IsNullOrWhiteSpace(configSetting))
return string.Empty;

// Section indexer is case-sensitive by default, so use GetChildren() to perform case-insensitive lookup
var child = config.GetChildren()
.FirstOrDefault(c => string.Equals(c.Key, configSetting, StringComparison.OrdinalIgnoreCase));
return child?.Value ?? string.Empty;
};
});
// Health checks
builder.Services.AddHealthChecks();

Expand Down
7 changes: 6 additions & 1 deletion TransactionProcessing.MerchantPos/appsettings.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@
//}
]
},

"ApiConfiguration": {
"SecurityService": "https://192.168.1.163:5001",
"TransactionProcessorACL": "http://192.168.1.163:5003",
"TransactionProcessorApi": "http://192.168.1.163:5002",
"TestHost": "http://192.168.1.163:9000"
},
"ConnectionStrings": {
"MerchantDb": "Data Source=merchant.db"
},
Expand Down
Loading