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 application settings to the new class PerformanceConfig (changes in App_Settings)

support5f03fdea359e
diff --git a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
index bcb228fd1..2373b178b 100644
--- a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
+++ b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
@@ -17,7 +17,7 @@ namespace Grand.Business.Common.Services.Seo
private readonly IRepository<EntityUrl> _urlEntityRepository;
private readonly ICacheBase _cacheBase;
- private readonly AppConfig _config;
+ private readonly PerformanceConfig _config;
#endregion
@@ -26,12 +26,9 @@ namespace Grand.Business.Common.Services.Seo
/// <summary>
/// Ctor
/// </summary>
- /// <param name="cacheBase">Cache manager</param>
- /// <param name="urlEntityRepository">URL Entity repository</param>
- /// <param name="languageSettings">Localization settings</param>
public SlugService(ICacheBase cacheBase,
IRepository<EntityUrl> urlEntityRepository,
- AppConfig config)
+ PerformanceConfig config)
{
_cacheBase = cacheBase;
_urlEntityRepository = urlEntityRepository;
diff --git a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs b/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
index dd7e97ac2..60812e022 100644
--- a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
+++ b/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
@@ -19,17 +19,7 @@ namespace Grand.Infrastructure.Configuration
/// Indicates whether we should Disable HostedService - BackgroundServiceTask
/// </summary>
public bool DisableHostedService { get; set; }
-
- /// <summary>
- /// A value indicating whether to ignore ACL rules (side-wide). It can significantly improve performance when enabled.
- /// </summary>
- public bool IgnoreAcl { get; set; }
-
- /// <summary>
- /// A value indicating whether to ignore "limit per store" rules (side-wide). It can significantly improve performance when enabled.
- /// </summary>
- public bool IgnoreStoreLimitations { get; set; }
-
+
/// <summary>
/// A value indicating whether to ignore the migration process
/// </summary>
@@ -57,11 +47,7 @@ namespace Grand.Infrastructure.Configuration
/// </summary>
public bool UseRoslynScripts { get; set; }
- /// <summary>
- /// Gets or sets a value indicating for default cache time in minutes
- /// </summary>
- public int DefaultCacheTimeMinutes { get; set; }
-
+
/// <summary>
/// Gets or sets a value indicating for cookie expires in hours - default 24 * 365 = 8760
/// </summary>
@@ -76,23 +62,13 @@ namespace Grand.Infrastructure.Configuration
/// Gets or sets a value for Cookie claim issuer
/// </summary>
public string CookieClaimsIssuer { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether mini profiler should be displayed in public store (used for debugging)
- /// </summary>
- public bool DisplayMiniProfilerInPublicStore { get; set; }
-
+
/// <summary>
/// A value indicating whether SEO friendly URLs with multiple languages are enabled
/// </summary>
public bool SeoFriendlyUrlsForLanguagesEnabled { get; set; }
public string SeoFriendlyUrlsDefaultCode { get; set; } = "en";
-
- /// <summary>
- /// A value indicating whether to load all search engine friendly names (slugs) on application startup
- /// </summary>
- public bool LoadAllUrlEntitiesOnStartup { get; set; }
-
+
/// <summary>
/// Gets or sets a value of "Cache-Control" header value for static content
/// </summary>
@@ -109,21 +85,13 @@ namespace Grand.Infrastructure.Configuration
/// </summary>
public bool DisplayFullErrorStack { get; set; }
- /// <summary>
- /// Gets or sets a value indicating whether we compress response
- /// </summary>
- public bool UseResponseCompression { get; set; }
-
+
/// <summary>
/// Gets or sets a value indicating whether use the default security headers for your application
/// </summary>
public bool UseDefaultSecurityHeaders { get; set; }
- /// <summary>
- /// Gets or sets a value indicating whether to enable html minification
- /// </summary>
- public bool UseHtmlMinification { get; set; }
- public bool HtmlMinificationErrors { get; set; }
+
public bool UseSessionStateTempDataProvider { get; set; }
@@ -147,22 +115,7 @@ namespace Grand.Infrastructure.Configuration
public bool UseRequestLocalization { get; set; }
public string DefaultRequestCulture { get; set; }
public IList<string> SupportedCultures { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether ignore InstallUrlMiddleware
- /// </summary>
- public bool IgnoreInstallUrlMiddleware { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether ignore DbVersionCheckMiddleware
- /// </summary>
- public bool IgnoreDbVersionCheckMiddleware { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether ignore IgnoreUsePoweredByMiddleware
- /// </summary>
- public bool IgnoreUsePoweredByMiddleware { get; set; }
-
+
/// <summary>
/// Gets or sets a value indicating - (Serilog) use middleware for smarter HTTP request logging
/// </summary>
diff --git a/src/Core/Grand.Infrastructure/Configuration/PerformanceConfig.cs b/src/Core/Grand.Infrastructure/Configuration/PerformanceConfig.cs
new file mode 100644
index 000000000..54c10e67b
--- /dev/null
+++ b/src/Core/Grand.Infrastructure/Configuration/PerformanceConfig.cs
@@ -0,0 +1,60 @@
+namespace Grand.Infrastructure.Configuration
+{
+ /// <summary>
+ /// Represents a Performance Config
+ /// </summary>
+ public partial class PerformanceConfig
+ {
+ /// <summary>
+ /// A value indicating whether to ignore ACL rules (side-wide). It can significantly improve performance when enabled.
+ /// </summary>
+ public bool IgnoreAcl { get; set; }
+
+ /// <summary>
+ /// A value indicating whether to ignore "limit per store" rules (side-wide). It can significantly improve performance when enabled.
+ /// </summary>
+ public bool IgnoreStoreLimitations { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating for default cache time in minutes
+ /// </summary>
+ public int DefaultCacheTimeMinutes { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether mini profiler should be displayed in public store (used for debugging)
+ /// </summary>
+ public bool DisplayMiniProfilerInPublicStore { get; set; }
+
+ /// <summary>
+ /// A value indicating whether to load all search engine friendly names (slugs) on application startup
+ /// </summary>
+ public bool LoadAllUrlEntitiesOnStartup { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether we compress response
+ /// </summary>
+ public bool UseResponseCompression { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether to enable html minification
+ /// </summary>
+ public bool UseHtmlMinification { get; set; }
+ public bool HtmlMinificationErrors { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether ignore InstallUrlMiddleware
+ /// </summary>
+ public bool IgnoreInstallUrlMiddleware { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether ignore DbVersionCheckMiddleware
+ /// </summary>
+ public bool IgnoreDbVersionCheckMiddleware { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether ignore IgnoreUsePoweredByMiddleware
+ /// </summary>
+ public bool IgnoreUsePoweredByMiddleware { get; set; }
+
+ }
+}
diff --git a/src/Core/Grand.Infrastructure/StartupBase.cs b/src/Core/Grand.Infrastructure/StartupBase.cs
index 297c65980..cb0d79ad3 100644
--- a/src/Core/Grand.Infrastructure/StartupBase.cs
+++ b/src/Core/Grand.Infrastructure/StartupBase.cs
@@ -190,7 +190,8 @@ namespace Grand.Infrastructure
services.AddWkhtmltopdf();
//add AppConfig configuration parameters
- var config = services.StartupConfig<AppConfig>(configuration.GetSection("Application"));
+ var applicationConfig = services.StartupConfig<AppConfig>(configuration.GetSection("Application"));
+ var performanceConfig = services.StartupConfig<PerformanceConfig>(configuration.GetSection("Performance"));
services.StartupConfig<HostingConfig>(configuration.GetSection("Hosting"));
services.StartupConfig<UrlRewriteConfig>(configuration.GetSection("UrlRewrite"));
services.StartupConfig<RedisConfig>(configuration.GetSection("Redis"));
@@ -210,11 +211,11 @@ namespace Grand.Infrastructure
CommonPath.WebHostEnvironment = hostingEnvironment.WebRootPath;
CommonPath.BaseDirectory = hostingEnvironment.ContentRootPath;
- CommonHelper.CacheTimeMinutes = config.DefaultCacheTimeMinutes;
- CommonHelper.CookieAuthExpires = config.CookieAuthExpires > 0 ? config.CookieAuthExpires : 24 * 365;
+ CommonHelper.CacheTimeMinutes = performanceConfig.DefaultCacheTimeMinutes;
+ CommonHelper.CookieAuthExpires = applicationConfig.CookieAuthExpires > 0 ? applicationConfig.CookieAuthExpires : 24 * 365;
- CommonHelper.IgnoreAcl = config.IgnoreAcl;
- CommonHelper.IgnoreStoreLimitations = config.IgnoreStoreLimitations;
+ CommonHelper.IgnoreAcl = performanceConfig.IgnoreAcl;
+ CommonHelper.IgnoreStoreLimitations = performanceConfig.IgnoreStoreLimitations;
var mvcCoreBuilder = services.AddMvcCore();
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ApplicationBuilderExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ApplicationBuilderExtensions.cs
index 89c182fe3..5d012696b 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/ApplicationBuilderExtensions.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/ApplicationBuilderExtensions.cs
@@ -251,9 +251,9 @@ namespace Grand.Web.Common.Infrastructure
if (!DataSettingsManager.DatabaseIsInstalled())
return;
- var appConfig = application.ApplicationServices.GetRequiredService<AppConfig>();
+ var performanceConfig = application.ApplicationServices.GetRequiredService<PerformanceConfig>();
//whether MiniProfiler should be displayed
- if (appConfig.DisplayMiniProfilerInPublicStore)
+ if (performanceConfig.DisplayMiniProfilerInPublicStore)
{
application.UseMiniProfiler();
}
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
index ead33bede..3dff90f30 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
@@ -238,7 +238,7 @@ namespace Grand.Web.Common.Infrastructure
options.IgnoredPaths.Add("/.well-known/pki-validation");
//determine who can access the MiniProfiler results
options.ResultsAuthorize = request =>
- !request.HttpContext.RequestServices.GetRequiredService<AppConfig>().DisplayMiniProfilerInPublicStore ||
+ !request.HttpContext.RequestServices.GetRequiredService<PerformanceConfig>().DisplayMiniProfilerInPublicStore ||
request.HttpContext.RequestServices.GetRequiredService<IPermissionService>().Authorize(StandardPermission.AccessAdminPanel).Result;
});
}
@@ -277,9 +277,9 @@ namespace Grand.Web.Common.Infrastructure
public static void AddHtmlMinification(this IServiceCollection services, IConfiguration configuration)
{
- var config = new AppConfig();
- configuration.GetSection("Application").Bind(config);
- if (config.UseHtmlMinification)
+ var performanceConfig = new PerformanceConfig();
+ configuration.GetSection("Performance").Bind(performanceConfig);
+ if (performanceConfig.UseHtmlMinification)
{
// Add WebMarkupMin services
services.AddWebMarkupMin(options =>
@@ -329,7 +329,7 @@ namespace Grand.Web.Common.Infrastructure
};
});
}
- if (config.HtmlMinificationErrors)
+ if (performanceConfig.HtmlMinificationErrors)
services.AddSingleton<IWmmLogger, WmmThrowExceptionLogger>();
}
diff --git a/src/Web/Grand.Web.Common/Startup/DbCheckStartup.cs b/src/Web/Grand.Web.Common/Startup/DbCheckStartup.cs
index 096e4b0ac..1b1fd0763 100644
--- a/src/Web/Grand.Web.Common/Startup/DbCheckStartup.cs
+++ b/src/Web/Grand.Web.Common/Startup/DbCheckStartup.cs
@@ -20,9 +20,9 @@ namespace Grand.Web.Common.Startup
return;
var serviceProvider = application.ApplicationServices;
- var appConfig = serviceProvider.GetRequiredService<AppConfig>();
+ var performanceConfig = serviceProvider.GetRequiredService<PerformanceConfig>();
- if(!appConfig.IgnoreDbVersionCheckMiddleware)
+ if(!performanceConfig.IgnoreDbVersionCheckMiddleware)
application.UseMiddleware<DbVersionCheckMiddleware>();
}
diff --git a/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs b/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs
index 582a943f7..6ff288c6e 100644
--- a/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs
+++ b/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs
@@ -73,6 +73,7 @@ namespace Grand.Web.Common.Startup
{
var serviceProvider = application.ApplicationServices;
var appConfig = serviceProvider.GetRequiredService<AppConfig>();
+ var performanceConfig = serviceProvider.GetRequiredService<PerformanceConfig>();
//add HealthChecks
application.UseGrandHealthChecks();
@@ -95,14 +96,14 @@ namespace Grand.Web.Common.Startup
}
//compression
- if (appConfig.UseResponseCompression)
+ if (performanceConfig.UseResponseCompression)
{
//gzip by default
application.UseResponseCompression();
}
//Add webMarkupMin
- if (appConfig.UseHtmlMinification)
+ if (performanceConfig.UseHtmlMinification)
{
application.UseHtmlMinification();
}
@@ -130,14 +131,14 @@ namespace Grand.Web.Common.Startup
application.UseGrandStaticFiles(appConfig);
//check whether database is installed
- if (!appConfig.IgnoreInstallUrlMiddleware)
+ if (!performanceConfig.IgnoreInstallUrlMiddleware)
application.UseInstallUrl();
//use HTTP session
application.UseSession();
//use powered by
- if (!appConfig.IgnoreUsePoweredByMiddleware)
+ if (!performanceConfig.IgnoreUsePoweredByMiddleware)
application.UsePoweredBy();
// Write streamlined request completion events, instead of the more verbose ones from the framework.
diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json
index a0e0231ae..22b08dc98 100644
--- a/src/Web/Grand.Web/App_Data/appsettings.json
+++ b/src/Web/Grand.Web/App_Data/appsettings.json
@@ -14,7 +14,6 @@
"Application": {
//Enable if you want to see the full error in production environment. It's ignored (always enabled) in development environment
"DisplayFullErrorStack": true,
-
//Value of "Cache-Control" header value for static content
"StaticFilesCacheControl": "public,max-age=31536000",
@@ -27,14 +26,6 @@
//Content-Security-Policy: object-src 'none'; form-action 'self'; frame-ancestors 'none'
"UseDefaultSecurityHeaders": false,
- //Flag for whether to enable html minification
- "UseHtmlMinification": false,
- "HtmlMinificationErrors": false,
-
- //Indicates whether to compress response (gzip by default)
- //You may want to disable it, for example, If you have an active IIS Dynamic Compression Module configured at the server level
- "UseResponseCompression": false,
-
//Disable upload extensions plugins/themes
"DisableUploadExtensions": false,
//A list of plugins to be ignored during start application - pattern
@@ -58,8 +49,7 @@
//https://github.com/dotnet/roslyn/wiki/Roslyn-Overview
"UseRoslynScripts": false,
- //Gets or sets a value indicating for default cache time in minutes"
- "DefaultCacheTimeMinutes": 60,
+
//Gets or sets a value indicating for cookie auth expires in hours - default 24 * 365 = 8760
"CookieAuthExpires": 8760,
@@ -75,22 +65,10 @@
//This is the one you should be targeting if your production environment fully runs on HTTPS
"CookieSecurePolicyAlways": false,
- //Gets or sets a value indicating whether mini profiler should be displayed in public store (used for debugging)
- "DisplayMiniProfilerInPublicStore": false,
-
//A value indicating whether SEO friendly URLs with multiple languages are enabled
"SeoFriendlyUrlsForLanguagesEnabled": false,
"SeoFriendlyUrlsDefaultCode": "en",
- //A value indicating whether to load all search engine friendly names (slugs) on application startup
- "LoadAllUrlEntitiesOnStartup": false,
-
- /// A value indicating whether to ignore ACL rules
- "IgnoreAcl": false,
-
- //A value indicating whether to ignore "limit per store" rules
- "IgnoreStoreLimitations": false,
-
//Use my request localization culture
"UseRequestLocalization": false,
"DefaultRequestCulture": "en-US",
@@ -98,20 +76,47 @@
"SupportedCultures": [ "en-US", "pl-PL" ],
//Indicates whether to disable hosted service - BackgroundServiceTask
"DisableHostedService": false,
+
//Enable if you want to clear /Plugins/bin directory on application startup
"ClearPluginShadowDirectoryOnStartup": true,
//For develop you should enable if you want to copy plugin dll files to directory /Plugins/bin on application startup
"PluginShadowCopy": true,
+
+ //(Serilog) Request logging - The package includes middleware for smarter HTTP request logging.
+ "UseSerilogRequestLogging": false
+ },
+ "Performance": {
+ //Flag for whether to enable html minification
+ "UseHtmlMinification": false,
+ "HtmlMinificationErrors": false,
+
+ //Indicates whether to compress response (gzip by default)
+ //You may want to disable it, for example, If you have an active IIS Dynamic Compression Module configured at the server level
+ "UseResponseCompression": false,
+
+ //Gets or sets a value indicating for default cache time in minutes"
+ "DefaultCacheTimeMinutes": 60,
+
+ //A value indicating whether to load all search engine friendly names (slugs) on application startup
+ "LoadAllUrlEntitiesOnStartup": false,
+
+ /// A value indicating whether to ignore ACL rules
+ "IgnoreAcl": false,
+
+ //A value indicating whether to ignore "limit per store" rules
+ "IgnoreStoreLimitations": false,
+
+ //Gets or sets a value indicating whether mini profiler should be displayed in public store (used for debugging)
+ "DisplayMiniProfilerInPublicStore": false,
+
//Indicates whether to ignore InstallUrlMiddleware
"IgnoreInstallUrlMiddleware": false,
//Indicates whether to ignore DbVersionCheckMiddleware
"IgnoreDbVersionCheckMiddleware": false,
//Indicates whether to ignore UsePoweredByMiddleware
- "IgnoreUsePoweredByMiddleware": false,
- //(Serilog) Request logging - The package includes middleware for smarter HTTP request logging.
- "UseSerilogRequestLogging": false
- },
+ "IgnoreUsePoweredByMiddleware": false
+ },
"Redis": {
///Enable the Publish/Subscribe messaging with redis to manage memory cache on every server
"RedisPubSubEnabled": false,
diff --git a/src/Web/Grand.Web/Views/Shared/_Layout.cshtml b/src/Web/Grand.Web/Views/Shared/_Layout.cshtml
index e1a1ab55d..875505221 100644
--- a/src/Web/Grand.Web/Views/Shared/_Layout.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/_Layout.cshtml
@@ -1,4 +1,4 @@
-@inject Grand.Infrastructure.Configuration.AppConfig config
+@inject Grand.Infrastructure.Configuration.PerformanceConfig config
<!DOCTYPE html>
<html use-lang="true">
<head>