Browse Source

Add `AbpMongoDbConventionalRegistrar_Tests`.

pull/10376/head
maliming 4 years ago
parent
commit
4e47e71a29
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 4
      framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs
  2. 9
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/AbpMongoDbConventionalRegistrar.cs
  3. 24
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbConventionalRegistrar_Tests.cs

4
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)

9
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<Type> GetExposedServiceTypes(Type type)
{
return new List<Type>()
{
typeof(IAbpMongoDbContext)
};
}
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{
return ServiceLifetime.Transient;

24
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<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);
}
}
}
Loading…
Cancel
Save