Browse Source
Add `AbpMongoDbConventionalRegistrar_Tests`.
pull/10376/head
maliming
5 years ago
No known key found for this signature in database
GPG Key ID: 96224957E51C89E
3 changed files with
36 additions and
1 deletions
-
framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs
-
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/AbpMongoDbConventionalRegistrar.cs
-
framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbConventionalRegistrar_Tests.cs
|
|
@ -1,5 +1,6 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Linq; |
|
|
using FluentValidation; |
|
|
using FluentValidation; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Volo.Abp.DependencyInjection; |
|
|
using Volo.Abp.DependencyInjection; |
|
|
@ -10,7 +11,8 @@ namespace Volo.Abp.FluentValidation |
|
|
{ |
|
|
{ |
|
|
protected override bool IsConventionalRegistrationDisabled(Type type) |
|
|
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) |
|
|
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type) |
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Volo.Abp.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); |
|
|
return !typeof(IAbpMongoDbContext).IsAssignableFrom(type) || type == typeof(AbpMongoDbContext) || base.IsConventionalRegistrationDisabled(type); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override List<Type> GetExposedServiceTypes(Type type) |
|
|
|
|
|
{ |
|
|
|
|
|
return new List<Type>() |
|
|
|
|
|
{ |
|
|
|
|
|
typeof(IAbpMongoDbContext) |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type) |
|
|
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type) |
|
|
{ |
|
|
{ |
|
|
return ServiceLifetime.Transient; |
|
|
return ServiceLifetime.Transient; |
|
|
|
|
|
@ -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<IAbpMongoDbContext>(); |
|
|
|
|
|
abpMongoDbContext.ShouldContain(x => x is TestAppMongoDbContext); |
|
|
|
|
|
abpMongoDbContext.ShouldContain(x => x is SecondDbContext); |
|
|
|
|
|
abpMongoDbContext.ShouldContain(x => x is ThirdDbContext); |
|
|
|
|
|
abpMongoDbContext.ShouldContain(x => x is FourthDbContext); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |