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 changes with FluentValidation

supportb08abf0bf8d9
diff --git a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
index 6a1891f8e..903be3677 100644
--- a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
+++ b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
@@ -18,7 +18,6 @@
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="StackExchange.Redis" Version="2.5.61" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
- <PackageReference Include="FluentValidation" Version="10.4.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="10.4.0" />
<PackageReference Include="Wkhtmltopdf.NetCore" Version="3.0.2" />
</ItemGroup>
diff --git a/src/Core/Grand.Infrastructure/StartupBase.cs b/src/Core/Grand.Infrastructure/StartupBase.cs
index bffe3fb0c..59250ac3f 100644
--- a/src/Core/Grand.Infrastructure/StartupBase.cs
+++ b/src/Core/Grand.Infrastructure/StartupBase.cs
@@ -1,5 +1,4 @@
using AutoMapper;
-using FluentValidation.AspNetCore;
using Grand.Domain.Data;
using Grand.Infrastructure.Caching.RabbitMq;
using Grand.Infrastructure.Configuration;
@@ -35,9 +34,9 @@ namespace Grand.Infrastructure
private static void InitDatabase(IServiceCollection services, IConfiguration configuration)
{
var advancedConfig = services.StartupConfig<AdvancedConfig>(configuration.GetSection("Advanced"));
- if(!string.IsNullOrEmpty(advancedConfig.DbConnectionString))
+ if (!string.IsNullOrEmpty(advancedConfig.DbConnectionString))
{
- DataSettingsManager.LoadDataSettings(new DataSettings() {
+ DataSettingsManager.LoadDataSettings(new DataSettings() {
ConnectionString = advancedConfig.DbConnectionString,
DbProvider = (DbProvider)advancedConfig.DbProvider,
});
@@ -72,24 +71,6 @@ namespace Grand.Infrastructure
AutoMapperConfig.Init(config);
}
- /// <summary>
- /// Add FluenValidation
- /// </summary>
- /// <param name="mvcCoreBuilder"></param>
- /// <param name="typeSearcher"></param>
- private static void AddFluentValidation(IMvcCoreBuilder mvcCoreBuilder, ITypeSearcher typeSearcher)
- {
- //Add fluentValidation
- mvcCoreBuilder.AddFluentValidation(configuration =>
- {
- var assemblies = typeSearcher.GetAssemblies();
- configuration.RegisterValidatorsFromAssemblies(assemblies);
- configuration.DisableDataAnnotationsValidation = true;
- //implicit/automatic validation of child properties
- configuration.ImplicitlyValidateChildProperties = true;
- });
- }
-
/// <summary>
/// Register type Converters
/// </summary>
@@ -185,7 +166,7 @@ namespace Grand.Infrastructure
});
cfg.ConfigureEndpoints(context);
});
- });
+ });
}
/// <summary>
@@ -276,9 +257,6 @@ namespace Grand.Infrastructure
//register mapper configurations
InitAutoMapper(typeSearcher);
- //add fluenvalidation
- AddFluentValidation(mvcBuilder, typeSearcher);
-
//Register custom type converters
RegisterTypeConverter(typeSearcher);
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
index b06c6a7ad..34551adc8 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
@@ -1,4 +1,5 @@
using Azure.Identity;
+using FluentValidation.AspNetCore;
using Grand.Business.Core.Interfaces.Authentication;
using Grand.Business.Core.Interfaces.Common.Configuration;
using Grand.Business.Core.Interfaces.Common.Security;
@@ -236,6 +237,17 @@ namespace Grand.Web.Common.Infrastructure
mvcBuilder.AddSessionStateTempDataProvider();
}
+ //Add fluentValidation
+ mvcBuilder.AddFluentValidation(configuration =>
+ {
+ var typeSearcher = new AppTypeSearcher();
+ var assemblies = typeSearcher.GetAssemblies();
+ configuration.RegisterValidatorsFromAssemblies(assemblies);
+ configuration.DisableDataAnnotationsValidation = true;
+ //implicit/automatic validation of child properties
+ configuration.ImplicitlyValidateChildProperties = true;
+ });
+
//MVC now serializes JSON with camel case names by default, use this code to avoid it
mvcBuilder.AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());