예제 #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));
예제 #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)));
예제 #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));
예제 #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)));
예제 #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));
예제 #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();
예제 #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();
예제 #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)));
예제 #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));
예제 #10
0
 /// <summary>
 /// 获取命名服务
 /// </summary>
 /// <param name="name">服务名称</param>
 public static object GetNamedService(this IServiceProvider provider, string name) =>
 provider.GetService(NamedType.Get(name));