public static void AddTransient <TInterface, TService>([NotNull] this IKeyedServiceRegistrar registrar, object key, Func <IServiceProvider, TService> implementationFactory) where TInterface : class where TService : class, TInterface { registrar.Services.AddTransient(implementationFactory); registrar.Services.AddTransient <TInterface, TService>(s => s.GetService <TService>()); registrar.Add <TInterface, TService>(key); }
public static void AddScoped <TInterface, TService>([NotNull] this IKeyedServiceRegistrar registrar, object key) where TInterface : class where TService : class, TInterface { registrar.Services.AddScoped <TService>(); registrar.Services.AddScoped <TInterface, TService>(); registrar.Add <TInterface, TService>(key); }
public static void Add <TInterface, TService>([NotNull] this IKeyedServiceRegistrar registrar, object key) where TService : class, TInterface { registrar.Add(typeof(TInterface), typeof(TService), key); }
/// <summary> /// Gets the registrar for the specified service container. /// </summary> /// <remarks>This is a singleton container, set up when this method is first called</remarks> /// <param name="serviceCollection">The service collection.</param> /// <returns>The keyed service registrar</returns> private static IKeyedServiceRegistrar GetRegistrar(IServiceCollection serviceCollection) { return(Registrar ?? (Registrar = new KeyedServiceRegistrar(serviceCollection))); }