|
|
@ -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,13 +26,18 @@ namespace Volo.Abp.DependencyInjection |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var serviceTypes = ExposedServiceExplorer.GetExposedServices(type); |
|
|
var exposedServiceTypes = ExposedServiceExplorer.GetExposedServices(type); |
|
|
|
|
|
|
|
|
TriggerServiceExposing(services, type, serviceTypes); |
|
|
TriggerServiceExposing(services, type, exposedServiceTypes); |
|
|
|
|
|
|
|
|
foreach (var serviceType in serviceTypes) |
|
|
foreach (var exposedServiceType in exposedServiceTypes) |
|
|
{ |
|
|
{ |
|
|
var serviceDescriptor = ServiceDescriptor.Describe(serviceType, type, lifeTime.Value); |
|
|
var serviceDescriptor = CreateServiceDescriptor( |
|
|
|
|
|
type, |
|
|
|
|
|
exposedServiceType, |
|
|
|
|
|
exposedServiceTypes, |
|
|
|
|
|
lifeTime.Value |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
if (dependencyAttribute?.ReplaceServices == true) |
|
|
if (dependencyAttribute?.ReplaceServices == true) |
|
|
{ |
|
|
{ |
|
|
@ -46,7 +53,63 @@ namespace Volo.Abp.DependencyInjection |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual ServiceDescriptor CreateServiceDescriptor( |
|
|
|
|
|
Type implementationType, |
|
|
|
|
|
Type exposingServiceType, |
|
|
|
|
|
List<Type> allExposingServiceTypes, |
|
|
|
|
|
ServiceLifetime lifeTime) |
|
|
|
|
|
{ |
|
|
|
|
|
if (lifeTime.IsIn(ServiceLifetime.Singleton, ServiceLifetime.Scoped)) |
|
|
|
|
|
{ |
|
|
|
|
|
var redirectedType = GetRedirectedTypeOrNull( |
|
|
|
|
|
implementationType, |
|
|
|
|
|
exposingServiceType, |
|
|
|
|
|
allExposingServiceTypes |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (redirectedType != null) |
|
|
|
|
|
{ |
|
|
|
|
|
return ServiceDescriptor.Describe( |
|
|
|
|
|
exposingServiceType, |
|
|
|
|
|
provider => provider.GetService(redirectedType), |
|
|
|
|
|
lifeTime |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ServiceDescriptor.Describe( |
|
|
|
|
|
exposingServiceType, |
|
|
|
|
|
implementationType, |
|
|
|
|
|
lifeTime |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual Type GetRedirectedTypeOrNull( |
|
|
|
|
|
Type implementationType, |
|
|
|
|
|
Type exposingServiceType, |
|
|
|
|
|
List<Type> allExposingServiceTypes) |
|
|
|
|
|
{ |
|
|
|
|
|
if (allExposingServiceTypes.Count < 2) |
|
|
|
|
|
{ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exposingServiceType == implementationType) |
|
|
|
|
|
{ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (allExposingServiceTypes.Contains(implementationType)) |
|
|
|
|
|
{ |
|
|
|
|
|
return implementationType; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return allExposingServiceTypes.FirstOrDefault( |
|
|
|
|
|
t => t != exposingServiceType && exposingServiceType.IsAssignableFrom(t) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected virtual DependencyAttribute GetDependencyAttributeOrNull(Type type) |
|
|
protected virtual DependencyAttribute GetDependencyAttributeOrNull(Type type) |
|
|
{ |
|
|
{ |
|
|
return type.GetCustomAttribute<DependencyAttribute>(true); |
|
|
return type.GetCustomAttribute<DependencyAttribute>(true); |
|
|
|