Skip to content

Commit 7e1ebcb

Browse files
authored
Add database settings binding and conditional Redis cache
Bind database settings from configuration and conditionally register Redis cache service based on the presence of Redis settings.
1 parent d192600 commit 7e1ebcb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ private static void AddCacheServices(IServiceCollection services, IConfiguration
4949
config.Bind("SharpCache", cacheSettings);
5050
services.AddSingleton(x => cacheSettings);
5151

52-
services.AddSingleton<RedisCacheService>();
52+
var dbSettings = new BotSharpDatabaseSettings();
53+
config.Bind("Database", dbSettings);
54+
55+
if (!string.IsNullOrEmpty(dbSettings.Redis))
56+
{
57+
services.AddSingleton<RedisCacheService>();
58+
return;
59+
}
60+
5361
services.AddSingleton<ICacheService>(sp => cacheSettings.CacheType switch
5462
{
5563
CacheType.RedisCache => ActivatorUtilities.CreateInstance<RedisCacheService>(sp),

0 commit comments

Comments
 (0)