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 c0633d9cc9..b4f56edc7d 100644 --- a/framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs +++ b/framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using FluentValidation; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; @@ -10,7 +11,8 @@ namespace Volo.Abp.FluentValidation { protected override bool IsConventionalRegistrationDisabled(Type type) { - return !typeof(IValidator).IsAssignableFrom(type) || base.IsConventionalRegistrationDisabled(type); + return !type.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IValidator<>)) || + base.IsConventionalRegistrationDisabled(type); } protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type) diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/AbpMongoDbConventionalRegistrar.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/AbpMongoDbConventionalRegistrar.cs index 4e4096ec36..4d10d7c030 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/AbpMongoDbConventionalRegistrar.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/AbpMongoDbConventionalRegistrar.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; @@ -11,6 +12,14 @@ namespace Volo.Abp.MongoDB.DependencyInjection return !typeof(IAbpMongoDbContext).IsAssignableFrom(type) || type == typeof(AbpMongoDbContext) || base.IsConventionalRegistrationDisabled(type); } + protected override List GetExposedServiceTypes(Type type) + { + return new List() + { + typeof(IAbpMongoDbContext) + }; + } + protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type) { return ServiceLifetime.Transient; diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbConventionalRegistrar_Tests.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbConventionalRegistrar_Tests.cs new file mode 100644 index 0000000000..61adb0c8a5 --- /dev/null +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbConventionalRegistrar_Tests.cs @@ -0,0 +1,24 @@ +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.MongoDB.TestApp.FourthContext; +using Volo.Abp.MongoDB.TestApp.SecondContext; +using Volo.Abp.MongoDB.TestApp.ThirdDbContext; +using Volo.Abp.TestApp.MongoDB; +using Xunit; + +namespace Volo.Abp.MongoDB +{ + [Collection(MongoTestCollection.Name)] + public class AbpMongoDbConventionalRegistrar_Tests : MongoDbTestBase + { + [Fact] + public void All_AbpMongoDbContext_Should_Exposed_IAbpMongoDbContext_Service() + { + var abpMongoDbContext = ServiceProvider.GetServices(); + abpMongoDbContext.ShouldContain(x => x is TestAppMongoDbContext); + abpMongoDbContext.ShouldContain(x => x is SecondDbContext); + abpMongoDbContext.ShouldContain(x => x is ThirdDbContext); + abpMongoDbContext.ShouldContain(x => x is FourthDbContext); + } + } +}