From 91a563d9959a6b296da832d0a330a265bcd3146a Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 9 Jun 2026 14:57:48 +0200 Subject: [PATCH] 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. --- EnvelopeGenerator.API/Program.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/EnvelopeGenerator.API/Program.cs b/EnvelopeGenerator.API/Program.cs index 38119574..a3da64df 100644 --- a/EnvelopeGenerator.API/Program.cs +++ b/EnvelopeGenerator.API/Program.cs @@ -270,12 +270,14 @@ try builder.Services.Configure(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