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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user