コード例 #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));