Browse Source

Refactor DefaultConventionalRegistrar

pull/1156/head
Halil ibrahim Kalkan 7 years ago
parent
commit
23286a955b
  1. 16
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/AutoRegistrationHelper.cs
  2. 21
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultConventionalRegistrar.cs

16
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/AutoRegistrationHelper.cs

@ -8,7 +8,7 @@ namespace Volo.Abp.DependencyInjection
{ {
public static class AutoRegistrationHelper public static class AutoRegistrationHelper
{ {
public static IEnumerable<Type> GetExposedServices(IServiceCollection services, Type type) public static List<Type> GetExposedServices(IServiceCollection services, Type type)
{ {
var typeInfo = type.GetTypeInfo(); var typeInfo = type.GetTypeInfo();
@ -23,10 +23,10 @@ namespace Volo.Abp.DependencyInjection
return customExposedServices; return customExposedServices;
} }
return GetDefaultExposedServices(services, type); return GetDefaultExposedServices(type);
} }
private static IEnumerable<Type> GetDefaultExposedServices(IServiceCollection services, Type type) private static List<Type> GetDefaultExposedServices(Type type)
{ {
var serviceTypes = new List<Type>(); var serviceTypes = new List<Type>();
@ -47,16 +47,6 @@ namespace Volo.Abp.DependencyInjection
} }
} }
var exposeActions = services.GetExposingActionList();
if (exposeActions.Any())
{
var args = new OnServiceExposingContext(type, serviceTypes);
foreach (var action in services.GetExposingActionList())
{
action(args);
}
}
return serviceTypes; return serviceTypes;
} }
} }

21
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultConventionalRegistrar.cs

@ -1,4 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -24,7 +26,11 @@ namespace Volo.Abp.DependencyInjection
return; return;
} }
foreach (var serviceType in AutoRegistrationHelper.GetExposedServices(services, type)) var serviceTypes = AutoRegistrationHelper.GetExposedServices(services, type);
TriggerServiceExposing(services, type, serviceTypes);
foreach (var serviceType in serviceTypes)
{ {
var serviceDescriptor = ServiceDescriptor.Describe(serviceType, type, lifeTime.Value); var serviceDescriptor = ServiceDescriptor.Describe(serviceType, type, lifeTime.Value);
@ -43,6 +49,19 @@ namespace Volo.Abp.DependencyInjection
} }
} }
protected virtual void TriggerServiceExposing(IServiceCollection services, Type type, List<Type> serviceTypes)
{
var exposeActions = services.GetExposingActionList();
if (exposeActions.Any())
{
var args = new OnServiceExposingContext(type, serviceTypes);
foreach (var action in exposeActions)
{
action(args);
}
}
}
protected virtual bool IsConventionalRegistrationDisabled(Type type) protected virtual bool IsConventionalRegistrationDisabled(Type type)
{ {
return type.IsDefined(typeof(DisableConventionalRegistrationAttribute), true); return type.IsDefined(typeof(DisableConventionalRegistrationAttribute), true);

Loading…
Cancel
Save