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.

Update fluentValidation (remove obsolete methods)

KrzysztofPajak7d0c1ec92b9a
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
index 3d19ec1f9..90fc83e20 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;
using FluentValidation.AspNetCore;
using Grand.Business.Core.Interfaces.Authentication;
using Grand.Business.Core.Interfaces.Common.Configuration;
@@ -11,6 +12,7 @@ using Grand.Infrastructure;
using Grand.Infrastructure.Configuration;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.TypeSearchers;
+using Grand.Infrastructure.Validators;
using Grand.SharedKernel.Extensions;
using Grand.Web.Common.Themes;
using Microsoft.AspNetCore.Builder;
@@ -24,6 +26,7 @@ using Microsoft.Extensions.WebEncoders;
using Newtonsoft.Json.Serialization;
using StackExchange.Redis;
using System.IO.Compression;
+using System.Reflection;
using System.Text.Encodings.Web;
using System.Text.Unicode;
using WebMarkupMin.AspNet.Common.Compressors;
@@ -236,14 +239,10 @@ namespace Grand.Web.Common.Infrastructure
}
//Add fluentValidation
- mvcBuilder.AddFluentValidation(configuration =>
- {
- var typeSearcher = new AppTypeSearcher();
- var assemblies = typeSearcher.GetAssemblies();
- configuration.RegisterValidatorsFromAssemblies(assemblies);
- configuration.DisableDataAnnotationsValidation = true;
- configuration.AutomaticValidationEnabled = false;
- });
+ services.AddFluentValidationClientsideAdapters();
+ var typeSearcher = new AppTypeSearcher();
+ var assemblies = typeSearcher.GetAssemblies();
+ services.AddValidatorsFromAssemblies(assemblies);
//MVC now serializes JSON with camel case names by default, use this code to avoid it
mvcBuilder.AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
diff --git a/src/Web/Grand.Web.Common/Startup/StartupApplication.cs b/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
index b31b0948b..f5fe2cab6 100644
--- a/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
+++ b/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
@@ -1,4 +1,3 @@
-using FluentValidation;
using Grand.Business.Core.Interfaces.Common.Pdf;
using Grand.Domain.Data;
using Grand.Infrastructure;
@@ -7,8 +6,6 @@ using Grand.Infrastructure.Caching.Message;
using Grand.Infrastructure.Caching.RabbitMq;
using Grand.Infrastructure.Caching.Redis;
using Grand.Infrastructure.Configuration;
-using Grand.Infrastructure.TypeSearchers;
-using Grand.Infrastructure.Validators;
using Grand.Web.Common.Localization;
using Grand.Web.Common.Middleware;
using Grand.Web.Common.Page;
@@ -23,7 +20,6 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using StackExchange.Redis;
-using System.Reflection;
namespace Grand.Web.Common.Startup
{
@@ -44,8 +40,6 @@ namespace Grand.Web.Common.Startup
RegisterContextService(services);
- RegisterValidators(services);
-
RegisterFramework(services);
}
@@ -89,33 +83,6 @@ namespace Grand.Web.Common.Startup
}
- private void RegisterValidators(IServiceCollection serviceCollection)
- {
- var typeSearcher = new AppTypeSearcher();
-
- var validators = typeSearcher.ClassesOfType(typeof(IValidator)).ToList();
- foreach (var validator in validators)
- {
- serviceCollection.AddTransient(validator);
- }
-
- //validator consumers
- var validatorconsumers = typeSearcher.ClassesOfType(typeof(IValidatorConsumer<>)).ToList();
- foreach (var consumer in validatorconsumers)
- {
- var types = consumer.GetTypeInfo().FindInterfaces((type, criteria) =>
- {
- var isMatch = type.GetTypeInfo().IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
- return isMatch;
- }, typeof(IValidatorConsumer<>));
- foreach (var item in types)
- {
- serviceCollection.AddScoped(item, consumer);
- }
-
- }
- }
-
private void RegisterFramework(IServiceCollection serviceCollection)
{
serviceCollection.AddScoped<IPageHeadBuilder, PageHeadBuilder>();