Ejemplo n.º 1
0
 /// <summary>
 /// 添加命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static IServiceCollection AddNamedTransient(this IServiceCollection services, string name, Type implementationType) =>
 services.FluentAdd(ServiceDescriptor.Transient(NamedType.Get(name, implementationType), implementationType));
Ejemplo n.º 2
0
 /// <summary>
 /// 添加命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static IServiceCollection AddNamedTransient <TService>(this IServiceCollection services, string name) =>
 services.FluentAdd(ServiceDescriptor.Transient(NamedType.Get(name, typeof(TService)), typeof(TService)));
Ejemplo n.º 3
0
 /// <summary>
 /// 添加命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static IServiceCollection AddNamedTransient(this IServiceCollection services, string name, Func <IServiceProvider, object> implementationFactory) =>
 services.FluentAdd(ServiceDescriptor.Transient(NamedType.Get(name, null), implementationFactory));
Ejemplo n.º 4
0
 /// <summary>
 /// 添加命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static IServiceCollection AddNamedSingleton <TService>(this IServiceCollection services, string name)
     where TService : class =>
 services.FluentAdd(ServiceDescriptor.Singleton(NamedType.Get(name, typeof(TService)), typeof(TService)));
Ejemplo n.º 5
0
 /// <summary>
 /// 添加命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static IServiceCollection AddNamedSingleton <TService>(this IServiceCollection services, string name, TService implementationInstance) =>
 services.FluentAdd(ServiceDescriptor.Singleton(NamedType.Get(name, typeof(TService)), implementationInstance));
Ejemplo n.º 6
0
 /// <summary>
 /// 获取命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static IEnumerable <object> GetNamedServices(this IServiceProvider provider, string name, Type serviceType) =>
 provider.GetServices(NamedType.Get(name, serviceType)).Where(serviceType.IsInstanceOfType).ToArray();
Ejemplo n.º 7
0
 /// <summary>
 /// 获取命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static IEnumerable <T> GetNamedServices <T>(this IServiceProvider provider, string name) =>
 provider.GetServices(NamedType.Get(name, typeof(T))).OfType <T>().ToArray();
Ejemplo n.º 8
0
 /// <summary>
 /// 获取命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static T GetNamedService <T>(this IServiceProvider provider, string name) =>
 (T)provider.GetService(NamedType.Get(name, typeof(T)));
Ejemplo n.º 9
0
 /// <summary>
 /// 获取命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static object GetRequiredNamedService(this IServiceProvider provider, string name, Type serviceType) =>
 provider.GetRequiredService(NamedType.Get(name, serviceType));
Ejemplo n.º 10
0
 /// <summary>
 /// 获取命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static object GetNamedService(this IServiceProvider provider, string name) =>
 provider.GetService(NamedType.Get(name));