diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs index a4f57b1b1f..526470b3ad 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs @@ -7,10 +7,15 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.AspNetCore.Mvc.DependencyInjection { - public class AbpAspNetCoreMvcConventionalRegistrar : DefaultConventionalRegistrar + public class AbpAspNetCoreMvcConventionalRegistrar : ConventionalRegistrarBase { public override void AddType(IServiceCollection services, Type type) { + if (IsConventionalRegistrationDisabled(type)) + { + return; + } + if (!IsMvcService(type)) { return; diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs index f9cbf3c13c..8a47e7fa17 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.Extensions.DependencyInjection; @@ -31,5 +32,23 @@ namespace Volo.Abp.DependencyInjection } public abstract void AddType(IServiceCollection services, Type type); + + protected virtual bool IsConventionalRegistrationDisabled(Type type) + { + return type.IsDefined(typeof(DisableConventionalRegistrationAttribute), true); + } + + protected virtual void TriggerServiceExposing(IServiceCollection services, Type implementationType, List serviceTypes) + { + var exposeActions = services.GetExposingActionList(); + if (exposeActions.Any()) + { + var args = new OnServiceExposingContext(implementationType, serviceTypes); + foreach (var action in exposeActions) + { + action(args); + } + } + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultConventionalRegistrar.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultConventionalRegistrar.cs index 9c5ee06d81..15361ece62 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultConventionalRegistrar.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultConventionalRegistrar.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; @@ -48,25 +46,7 @@ namespace Volo.Abp.DependencyInjection } } } - - protected virtual void TriggerServiceExposing(IServiceCollection services, Type type, List serviceTypes) - { - var exposeActions = services.GetExposingActionList(); - if (exposeActions.Any()) - { - var args = new OnServiceExposingContext(type, serviceTypes); - foreach (var action in exposeActions) - { - action(args); - } - } - } - - protected virtual bool IsConventionalRegistrationDisabled(Type type) - { - return type.IsDefined(typeof(DisableConventionalRegistrationAttribute), true); - } - + protected virtual DependencyAttribute GetDependencyAttributeOrNull(Type type) { return type.GetCustomAttribute(true); diff --git a/framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs b/framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs index 9641b438b0..d51e4728ca 100644 --- a/framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs +++ b/framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs @@ -1,14 +1,20 @@ using System; +using System.Collections.Generic; using FluentValidation; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; namespace Volo.Abp.FluentValidation { - public class AbpFluentValidationConventionalRegistrar : DefaultConventionalRegistrar + public class AbpFluentValidationConventionalRegistrar : ConventionalRegistrarBase { public override void AddType(IServiceCollection services, Type type) { + if (IsConventionalRegistrationDisabled(type)) + { + return; + } + if (!typeof(IValidator).IsAssignableFrom(type)) { return; @@ -20,8 +26,12 @@ namespace Volo.Abp.FluentValidation return; } + var serviceType = typeof(IValidator<>).MakeGenericType(validatingType); + + TriggerServiceExposing(services, type, new List{ serviceType }); + services.AddTransient( - typeof(IValidator<>).MakeGenericType(validatingType), + serviceType, type ); }