Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Minor improvements - move Redis settings to the new class (changes in App_Settings)

supportc997cded8c2c
diff --git a/src/Core/Grand.Infrastructure/Caching/Redis/RedisMessageBus.cs b/src/Core/Grand.Infrastructure/Caching/Redis/RedisMessageBus.cs
index 55d43ec64..088b9b110 100644
--- a/src/Core/Grand.Infrastructure/Caching/Redis/RedisMessageBus.cs
+++ b/src/Core/Grand.Infrastructure/Caching/Redis/RedisMessageBus.cs
@@ -11,15 +11,15 @@ namespace Grand.Infrastructure.Caching.Redis
{
private readonly ISubscriber _subscriber;
private readonly IServiceProvider _serviceProvider;
- private readonly AppConfig _appConfig;
+ private readonly RedisConfig _redisConfig;
private static readonly string _clientId = Guid.NewGuid().ToString("N");
- public RedisMessageBus(ISubscriber subscriber, IServiceProvider serviceProvider, AppConfig appConfig)
+ public RedisMessageBus(ISubscriber subscriber, IServiceProvider serviceProvider, RedisConfig redisConfig)
{
_subscriber = subscriber;
_serviceProvider = serviceProvider;
- _appConfig = appConfig;
+ _redisConfig = redisConfig;
SubscribeAsync();
}
@@ -34,7 +34,7 @@ namespace Grand.Infrastructure.Caching.Redis
MessageType = msg.MessageType
};
var message = JsonConvert.SerializeObject(clientmsg);
- await pub.PublishAsync(_appConfig.RedisPubSubChannel, message);
+ await pub.PublishAsync(_redisConfig.RedisPubSubChannel, message);
}
catch(Exception ex)
{
@@ -46,7 +46,7 @@ namespace Grand.Infrastructure.Caching.Redis
{
var sub = _subscriber.Multiplexer.GetSubscriber();
- sub.SubscribeAsync(_appConfig.RedisPubSubChannel, async (_, redisValue) =>
+ sub.SubscribeAsync(_redisConfig.RedisPubSubChannel, async (_, redisValue) =>
{
try
{
diff --git a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs b/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
index f79b11b20..741c6ec2e 100644
--- a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
+++ b/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
@@ -46,30 +46,7 @@ namespace Grand.Infrastructure.Configuration
/// </summary>
public bool PluginShadowCopy { get; set; }
- /// <summary>
- /// Enable the Publish/Subscribe messaging with redis to manage memory cache on every server
- /// </summary>
- public bool RedisPubSubEnabled { get; set; }
-
- /// <summary>
- /// Redis connection string. Used when Redis Publish/Subscribe is enabled
- /// </summary>
- public string RedisPubSubConnectionString { get; set; }
-
- /// <summary>
- /// Messages sent by other clients to these channels will be pushed by Redis to all the subscribed clients. It must me the same value on every server
- /// </summary>
- public string RedisPubSubChannel { get; set; }
-
- /// <summary>
- /// Indicates whether we should use Redis server for persist keys - required in farm scenario
- /// </summary>
- public bool PersistKeysToRedis { get; set; }
-
- /// <summary>
- /// Redis connection string. Used when PersistKeysToRedis is enabled
- /// </summary>
- public string PersistKeysToRedisUrl { get; set; }
+
/// <summary>
diff --git a/src/Core/Grand.Infrastructure/Configuration/RedisConfig.cs b/src/Core/Grand.Infrastructure/Configuration/RedisConfig.cs
new file mode 100644
index 000000000..615ce3fcf
--- /dev/null
+++ b/src/Core/Grand.Infrastructure/Configuration/RedisConfig.cs
@@ -0,0 +1,31 @@
+namespace Grand.Infrastructure.Configuration
+{
+ public partial class RedisConfig
+ {
+ /// <summary>
+ /// Enable the Publish/Subscribe messaging with redis to manage memory cache on every server
+ /// </summary>
+ public bool RedisPubSubEnabled { get; set; }
+
+ /// <summary>
+ /// Redis connection string. Used when Redis Publish/Subscribe is enabled
+ /// </summary>
+ public string RedisPubSubConnectionString { get; set; }
+
+ /// <summary>
+ /// Messages sent by other clients to these channels will be pushed by Redis to all the subscribed clients. It must me the same value on every server
+ /// </summary>
+ public string RedisPubSubChannel { get; set; }
+
+ /// <summary>
+ /// Indicates whether we should use Redis server for persist keys - required in farm scenario
+ /// </summary>
+ public bool PersistKeysToRedis { get; set; }
+
+ /// <summary>
+ /// Redis connection string. Used when PersistKeysToRedis is enabled
+ /// </summary>
+ public string PersistKeysToRedisUrl { get; set; }
+
+ }
+}
diff --git a/src/Core/Grand.Infrastructure/StartupBase.cs b/src/Core/Grand.Infrastructure/StartupBase.cs
index 13cf2fedb..5d6be3152 100644
--- a/src/Core/Grand.Infrastructure/StartupBase.cs
+++ b/src/Core/Grand.Infrastructure/StartupBase.cs
@@ -147,15 +147,18 @@ namespace Grand.Infrastructure
/// Add Mass Transit rabitMq message broker
/// </summary>
/// <param name="services"></param>
- private static void AddMassTransitRabbitMq(IServiceCollection services, AppConfig config, AppTypeSearcher typeSearcher)
+ private static void AddMassTransitRabbitMq(IServiceCollection services, IConfiguration configuration, AppTypeSearcher typeSearcher)
{
+ var config = new AppConfig();
+ configuration.GetSection("Application").Bind(config);
+
if (!config.RabbitEnabled) return;
services.AddMassTransit(x =>
{
x.AddConsumers(q => !q.Equals(typeof(CacheMessageEventConsumer)), typeSearcher.GetAssemblies().ToArray());
// reddits have more priority
- if (!config.RedisPubSubEnabled && config.RabbitCachePubSubEnabled)
+ if (config.RabbitCachePubSubEnabled)
{
x.AddConsumer<CacheMessageEventConsumer>().Endpoint(t => t.Name = config.RabbitCacheReceiveEndpoint);
}
@@ -188,13 +191,10 @@ namespace Grand.Infrastructure
//add AppConfig configuration parameters
var config = services.StartupConfig<AppConfig>(configuration.GetSection("Application"));
- //add hosting configuration parameters
services.StartupConfig<HostingConfig>(configuration.GetSection("Hosting"));
- //add api configuration parameters
+ services.StartupConfig<RedisConfig>(configuration.GetSection("Redis"));
services.StartupConfig<ApiConfig>(configuration.GetSection("Api"));
- //add grand.web api token config
services.StartupConfig<GrandWebApiConfig>(configuration.GetSection("GrandWebApi"));
- //add litedb configuration parameters
services.StartupConfig<LiteDbConfig>(configuration.GetSection("LiteDb"));
//set base application path
@@ -262,14 +262,11 @@ namespace Grand.Infrastructure
//Register custom type converters
RegisterTypeConverter(typeSearcher);
- var config = new AppConfig();
- configuration.GetSection("Application").Bind(config);
-
//add mediator
AddMediator(services, typeSearcher);
//Add MassTransit
- AddMassTransitRabbitMq(services, config, typeSearcher);
+ AddMassTransitRabbitMq(services, configuration, typeSearcher);
//Register startup
var instancesAfter = startupConfigurations
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
index 5ca1fc436..ead33bede 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
@@ -99,9 +99,11 @@ namespace Grand.Web.Common.Infrastructure
/// <summary>
/// Adds data protection services
/// </summary>
- /// <param name="services">Collection of service descriptors</param>
- public static void AddGrandDataProtection(this IServiceCollection services, AppConfig config)
+ public static void AddGrandDataProtection(this IServiceCollection services, IConfiguration configuration)
{
+ var config = new RedisConfig();
+ configuration.GetSection("Redis").Bind(config);
+
if (config.PersistKeysToRedis)
{
services.AddDataProtection(opt => opt.ApplicationDiscriminator = "grandnode")
diff --git a/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs b/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs
index fcc47bf63..582a943f7 100644
--- a/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs
+++ b/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs
@@ -61,7 +61,7 @@ namespace Grand.Web.Common.Startup
});
//add data protection
- services.AddGrandDataProtection(config);
+ services.AddGrandDataProtection(configuration);
}
/// <summary>
diff --git a/src/Web/Grand.Web.Common/Startup/StartupApplication.cs b/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
index 6383cea32..c6daecd67 100644
--- a/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
+++ b/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
@@ -38,11 +38,7 @@ namespace Grand.Web.Common.Startup
/// <param name="config">Config</param>
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
- var config = new AppConfig();
-
- configuration.GetSection("Application").Bind(config);
-
- RegisterCache(services, config);
+ RegisterCache(services, configuration);
RegisterContextService(services);
@@ -58,8 +54,11 @@ namespace Grand.Web.Common.Startup
public int Priority => 0;
public bool BeforeConfigure => false;
- private void RegisterCache(IServiceCollection serviceCollection, AppConfig config)
+ private void RegisterCache(IServiceCollection serviceCollection, IConfiguration configuration)
{
+ var config = new RedisConfig();
+ configuration.GetSection("Redis").Bind(config);
+
serviceCollection.AddSingleton<ICacheBase, MemoryCacheBase>();
if (config.RedisPubSubEnabled)
@@ -70,7 +69,9 @@ namespace Grand.Web.Common.Startup
serviceCollection.AddSingleton<ICacheBase, RedisMessageCacheManager>();
return;
}
- if (config.RabbitCachePubSubEnabled && config.RabbitEnabled)
+ var application = new AppConfig();
+ configuration.GetSection("Application").Bind(config);
+ if (application.RabbitCachePubSubEnabled && application.RabbitEnabled)
{
serviceCollection.AddSingleton<ICacheBase, RabbitMqMessageCacheManager>();
}
diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json
index ba1e92c55..735dee7b8 100644
--- a/src/Web/Grand.Web/App_Data/appsettings.json
+++ b/src/Web/Grand.Web/App_Data/appsettings.json
@@ -78,12 +78,6 @@
"AmazonRegion": "",
"AmazonDistributionDomainName": "", //Domain name for cloudfront distribution
- ///Enable the Publish/Subscribe messaging with redis to manage memory cache on every server
- "RedisPubSubEnabled": false,
- "RedisPubSubConnectionString": "127.0.0.1:6379,allowAdmin=true",
- "RedisPubSubChannel": "channel",
- "PersistKeysToRedis": false,
- "PersistKeysToRedisUrl": "127.0.0.1:6379,allowAdmin=true,defaultDatabase=1",
//Enable RabbitMq
"RabbitEnabled": false,
@@ -153,6 +147,16 @@
//(Serilog) Request logging - The package includes middleware for smarter HTTP request logging.
"UseSerilogRequestLogging": false
},
+
+ "Redis": {
+ ///Enable the Publish/Subscribe messaging with redis to manage memory cache on every server
+ "RedisPubSubEnabled": false,
+ "RedisPubSubConnectionString": "127.0.0.1:6379,allowAdmin=true",
+ "RedisPubSubChannel": "channel",
+ "PersistKeysToRedis": false,
+ "PersistKeysToRedisUrl": "127.0.0.1:6379,allowAdmin=true,defaultDatabase=1"
+ },
+
"FacebookSettings": {
//Facebook-assigned App ID
"AppId": "",