mirror of https://github.com/abpframework/abp.git
committed by
GitHub
12 changed files with 228 additions and 260 deletions
@ -1,27 +1,22 @@ |
|||||
using System; |
using System; |
||||
using Microsoft.Extensions.DependencyInjection; |
using System.Collections.Generic; |
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
namespace Volo.Abp.BackgroundWorkers.Quartz |
namespace Volo.Abp.BackgroundWorkers.Quartz |
||||
{ |
{ |
||||
public class AbpQuartzConventionalRegistrar : DefaultConventionalRegistrar |
public class AbpQuartzConventionalRegistrar : DefaultConventionalRegistrar |
||||
{ |
{ |
||||
public override void AddType(IServiceCollection services, Type type) |
protected override bool IsConventionalRegistrationDisabled(Type type) |
||||
{ |
{ |
||||
if (!typeof(IQuartzBackgroundWorker).IsAssignableFrom(type)) |
return !typeof(IQuartzBackgroundWorker).IsAssignableFrom(type) || base.IsConventionalRegistrationDisabled(type); |
||||
{ |
} |
||||
return; |
|
||||
} |
|
||||
|
|
||||
var dependencyAttribute = GetDependencyAttributeOrNull(type); |
|
||||
var lifeTime = GetLifeTimeOrNull(type, dependencyAttribute); |
|
||||
|
|
||||
if (lifeTime == null) |
protected override List<Type> GetExposedServiceTypes(Type type) |
||||
|
{ |
||||
|
return new List<Type>() |
||||
{ |
{ |
||||
return; |
typeof(IQuartzBackgroundWorker) |
||||
} |
}; |
||||
|
|
||||
services.Add(ServiceDescriptor.Describe(typeof(IQuartzBackgroundWorker), type, lifeTime.Value)); |
|
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,29 +1,28 @@ |
|||||
using System; |
using System; |
||||
using System.Reflection; |
using System.Collections.Generic; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
namespace Volo.Abp.MongoDB.DependencyInjection |
namespace Volo.Abp.MongoDB.DependencyInjection |
||||
{ |
{ |
||||
public class AbpMongoDbConventionalRegistrar : DefaultConventionalRegistrar |
public class AbpMongoDbConventionalRegistrar : DefaultConventionalRegistrar |
||||
{ |
{ |
||||
public override void AddType(IServiceCollection services, Type type) |
protected override bool IsConventionalRegistrationDisabled(Type type) |
||||
{ |
{ |
||||
if (!typeof(IAbpMongoDbContext).IsAssignableFrom(type) || type == typeof(AbpMongoDbContext)) |
return !typeof(IAbpMongoDbContext).IsAssignableFrom(type) || type == typeof(AbpMongoDbContext) || base.IsConventionalRegistrationDisabled(type); |
||||
{ |
} |
||||
return; |
|
||||
} |
|
||||
|
|
||||
var dependencyAttribute = GetDependencyAttributeOrNull(type); |
|
||||
var lifeTime = GetLifeTimeOrNull(type, dependencyAttribute); |
|
||||
|
|
||||
if (lifeTime == null) |
protected override List<Type> GetExposedServiceTypes(Type type) |
||||
|
{ |
||||
|
return new List<Type>() |
||||
{ |
{ |
||||
return; |
typeof(IAbpMongoDbContext) |
||||
} |
}; |
||||
|
} |
||||
|
|
||||
services.Add(ServiceDescriptor.Describe(typeof(IAbpMongoDbContext), type, ServiceLifetime.Transient)); |
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type) |
||||
|
{ |
||||
|
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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue