Browse Source

Add `GetDefaultLifeTimeOrNull` method.

pull/10376/head
maliming 4 years ago
parent
commit
373714a08a
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 8
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/DependencyInjection/AbpWebAssemblyConventionalRegistrar.cs
  2. 8
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalRegistrar.cs
  3. 8
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpSignalRConventionalRegistrar.cs
  4. 7
      framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperConventionalRegistrar.cs
  5. 7
      framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/AbpQuartzConventionalRegistrar.cs
  6. 7
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs
  7. 9
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/AbpRepositoryConventionalRegistrar.cs
  8. 15
      framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs
  9. 8
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/AbpMongoDbConventionalRegistrar.cs

8
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/DependencyInjection/AbpWebAssemblyConventionalRegistrar.cs

@ -1,5 +1,4 @@
using System;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
@ -18,12 +17,7 @@ namespace Volo.Abp.AspNetCore.Components.DependencyInjection
return typeof(ComponentBase).IsAssignableFrom(type);
}
protected override ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute)
{
return dependencyAttribute?.Lifetime ?? GetWebAssemblyServiceLifetime(type);
}
protected virtual ServiceLifetime GetWebAssemblyServiceLifetime(Type type)
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{
return ServiceLifetime.Transient;
}

8
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalRegistrar.cs

@ -1,5 +1,4 @@
using System;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
@ -37,12 +36,7 @@ namespace Volo.Abp.AspNetCore.Mvc.DependencyInjection
return typeof(ViewComponent).IsAssignableFrom(type) || type.IsDefined(typeof(ViewComponentAttribute), true);
}
protected override ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute)
{
return dependencyAttribute?.Lifetime ?? GetMvcServiceLifetime(type);
}
protected virtual ServiceLifetime GetMvcServiceLifetime(Type type)
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{
return ServiceLifetime.Transient;
}

8
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpSignalRConventionalRegistrar.cs

@ -1,5 +1,4 @@
using System;
using JetBrains.Annotations;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
@ -18,12 +17,7 @@ namespace Volo.Abp.AspNetCore.SignalR
return typeof(Hub).IsAssignableFrom(type);
}
protected override ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute)
{
return dependencyAttribute?.Lifetime ?? GetSignalRServiceLifetime(type);
}
protected virtual ServiceLifetime GetSignalRServiceLifetime(Type type)
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{
return ServiceLifetime.Transient;
}

7
framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperConventionalRegistrar.cs

@ -22,12 +22,7 @@ namespace Volo.Abp.AutoMapper
return !OpenTypes.Any(type.ImplementsGenericInterface) || base.IsConventionalRegistrationDisabled(type);
}
protected override ServiceLifetime? GetLifeTimeOrNull(Type type, DependencyAttribute dependencyAttribute)
{
return base.GetLifeTimeOrNull(type, dependencyAttribute) ?? GetAutoMapperServiceLifetime(type);
}
protected virtual ServiceLifetime GetAutoMapperServiceLifetime(Type type)
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{
return ServiceLifetime.Transient;
}

7
framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/AbpQuartzConventionalRegistrar.cs

@ -13,9 +13,10 @@ namespace Volo.Abp.BackgroundWorkers.Quartz
protected override List<Type> GetExposedServiceTypes(Type type)
{
var serviceTypes = base.GetExposedServiceTypes(type);
serviceTypes.AddIfNotContains(typeof(IQuartzBackgroundWorker));
return serviceTypes;
return new List<Type>()
{
typeof(IQuartzBackgroundWorker)
};
}
}
}

7
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs

@ -59,7 +59,7 @@ namespace Volo.Abp.DependencyInjection
protected virtual ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute)
{
return dependencyAttribute?.Lifetime ?? GetServiceLifetimeFromClassHierarchy(type);
return dependencyAttribute?.Lifetime ?? GetServiceLifetimeFromClassHierarchy(type) ?? GetDefaultLifeTimeOrNull(type);
}
protected virtual ServiceLifetime? GetServiceLifetimeFromClassHierarchy(Type type)
@ -82,6 +82,11 @@ namespace Volo.Abp.DependencyInjection
return null;
}
protected virtual ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{
return null;
}
protected virtual List<Type> GetExposedServiceTypes(Type type)
{
return ExposedServiceExplorer.GetExposedServices(type);

9
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/AbpRepositoryConventionalRegistrar.cs

@ -30,16 +30,9 @@ namespace Volo.Abp.Domain.Repositories
.ToList();
}
protected override ServiceLifetime? GetServiceLifetimeFromClassHierarchy(Type type)
{
return base.GetServiceLifetimeFromClassHierarchy(type) ??
GetRepositoryServiceLifetime(type);
}
protected virtual ServiceLifetime GetRepositoryServiceLifetime(Type type)
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{
return ServiceLifetime.Transient;
}
}
}

15
framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs

@ -13,27 +13,16 @@ namespace Volo.Abp.FluentValidation
return !typeof(IValidator).IsAssignableFrom(type) || base.IsConventionalRegistrationDisabled(type);
}
protected override ServiceLifetime? GetLifeTimeOrNull(Type type, DependencyAttribute dependencyAttribute)
{
return base.GetLifeTimeOrNull(type, dependencyAttribute) ?? GetValidatorServiceLifetime(type);
}
protected virtual ServiceLifetime GetValidatorServiceLifetime(Type type)
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{
return ServiceLifetime.Transient;
}
protected override List<Type> GetExposedServiceTypes(Type type)
{
var validatingType = GetFirstGenericArgumentOrNull(type, 1);
if (validatingType == null)
{
return new List<Type>();
}
return new List<Type>()
{
typeof(IValidator<>).MakeGenericType(validatingType)
typeof(IValidator<>).MakeGenericType(GetFirstGenericArgumentOrNull(type, 1))
};
}

8
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DependencyInjection/AbpMongoDbConventionalRegistrar.cs

@ -1,5 +1,4 @@
using System;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
@ -12,12 +11,7 @@ namespace Volo.Abp.MongoDB.DependencyInjection
return !typeof(IAbpMongoDbContext).IsAssignableFrom(type) || type == typeof(AbpMongoDbContext) || base.IsConventionalRegistrationDisabled(type);
}
protected override ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute)
{
return dependencyAttribute?.Lifetime ?? GetAbpMongoDbContextLifetime(type);
}
protected virtual ServiceLifetime GetAbpMongoDbContextLifetime(Type type)
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{
return ServiceLifetime.Transient;
}

Loading…
Cancel
Save