Refactor SQL cache configuration in Program.cs

Simplified the configuration of the distributed SQL Server cache by using the `Bind` method to map all properties from the `Cache:SqlServer` configuration section directly to the `options` object.

Added a fallback to ensure the `ConnectionString` is set to `connStr` if it is empty or whitespace.
This commit is contained in:
2026-06-09 14:57:48 +02:00
parent 308cdd03f2
commit 91a563d995

View File

@@ -270,12 +270,14 @@ try
builder.Services.Configure<CacheOptions>(config.GetSection(CacheOptions.SectionName));
// Distributed Cache - SQL Server
var sqlCacheConfig = config.GetSection("Cache:SqlServer");
builder.Services.AddDistributedSqlServerCache(options =>
{
options.ConnectionString = sqlCacheConfig["ConnectionString"] ?? connStr;
options.SchemaName = sqlCacheConfig["SchemaName"];
options.TableName = sqlCacheConfig["TableName"];
config.GetSection("Cache:SqlServer").Bind(options);
if (string.IsNullOrWhiteSpace(options.ConnectionString))
{
options.ConnectionString = connStr;
}
});
// Envelope generator serives