mirror of https://github.com/abpframework/abp.git
9 changed files with 171 additions and 54 deletions
@ -0,0 +1,31 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Microsoft.Extensions.DependencyInjection; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extensions for working with <see cref="ServiceDescriptor"/>.
|
||||
|
/// </summary>
|
||||
|
public static class ServiceDescriptorExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Normalizes the implementation instance data between keyed and not keyed services.
|
||||
|
/// </summary>
|
||||
|
/// <param name="descriptor">
|
||||
|
/// The <see cref="ServiceDescriptor"/> to normalize.
|
||||
|
/// </param>
|
||||
|
/// <returns>
|
||||
|
/// The appropriate implementation instance from the service descriptor.
|
||||
|
/// </returns>
|
||||
|
public static object? NormalizedImplementationInstance(this ServiceDescriptor descriptor) => descriptor.IsKeyedService ? descriptor.KeyedImplementationInstance : descriptor.ImplementationInstance; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Normalizes the implementation type data between keyed and not keyed services.
|
||||
|
/// </summary>
|
||||
|
/// <param name="descriptor">
|
||||
|
/// The <see cref="ServiceDescriptor"/> to normalize.
|
||||
|
/// </param>
|
||||
|
/// <returns>
|
||||
|
/// The appropriate implementation type from the service descriptor.
|
||||
|
/// </returns>
|
||||
|
public static Type? NormalizedImplementationType(this ServiceDescriptor descriptor) => descriptor.IsKeyedService ? descriptor.KeyedImplementationType : descriptor.ImplementationType; |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
public class CachedServiceDescriptor |
||||
|
{ |
||||
|
private object? Key { get; } |
||||
|
|
||||
|
private Type ServiceType { get; } |
||||
|
|
||||
|
public CachedServiceDescriptor(object? key, Type serviceType) |
||||
|
{ |
||||
|
Key = key; |
||||
|
ServiceType = serviceType; |
||||
|
} |
||||
|
|
||||
|
public override bool Equals(object? obj) |
||||
|
{ |
||||
|
return obj is CachedServiceDescriptor descriptor && |
||||
|
Key == descriptor.Key && |
||||
|
ServiceType == descriptor.ServiceType; |
||||
|
} |
||||
|
|
||||
|
public override int GetHashCode() |
||||
|
{ |
||||
|
var keyHashCode = Key?.GetHashCode() ?? 0; |
||||
|
return keyHashCode ^ ServiceType.GetHashCode(); |
||||
|
} |
||||
|
} |
||||
@ -1,14 +1,19 @@ |
|||||
using System; |
using System; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
|
||||
namespace Volo.Abp.DependencyInjection; |
namespace Volo.Abp.DependencyInjection; |
||||
|
|
||||
public interface ICachedServiceProviderBase : IServiceProvider |
public interface ICachedServiceProviderBase : IKeyedServiceProvider |
||||
{ |
{ |
||||
T GetService<T>(T defaultValue); |
T GetService<T>(T defaultValue); |
||||
|
|
||||
object GetService(Type serviceType, object defaultValue); |
object GetService(Type serviceType, object defaultValue); |
||||
|
|
||||
T GetService<T>(Func<IServiceProvider, object> factory); |
T GetService<T>(Func<IServiceProvider, object> factory); |
||||
|
|
||||
object GetService(Type serviceType, Func<IServiceProvider, object> factory); |
object GetService(Type serviceType, Func<IServiceProvider, object> factory); |
||||
} |
|
||||
|
T GetKeyedService<T>(object? serviceKey); |
||||
|
|
||||
|
T GetRequiredKeyedService<T>(object? serviceKey); |
||||
|
} |
||||
|
|||||
Loading…
Reference in new issue