/// <summary> /// Adds a singleton service of the type specified in <paramref name="serviceType"/> with an /// instance specified in <paramref name="implementationInstance"/> to the specified <see cref="IServiceCollection"/>. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param> /// <param name="serviceType">The type of the service to register.</param> /// <param name="implementationInstance">The instance of the service.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <seealso cref="ServiceLifetime.Singleton"/> public static IServiceCollection AddSingleton( this PollyServiceCollection services, Type serviceType, object implementationInstance) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (serviceType == null) { throw new ArgumentNullException(nameof(serviceType)); } if (implementationInstance == null) { throw new ArgumentNullException(nameof(implementationInstance)); } var serviceDescriptor = new ServiceDescriptor(serviceType, implementationInstance); services.Add(serviceDescriptor); return(services); }
private static IServiceCollection Add( PollyServiceCollection collection, Type serviceType, Func <IServiceProvider, object> implementationFactory, ServiceLifetime lifetime) { var descriptor = new ServiceDescriptor(serviceType, implementationFactory, lifetime); collection.Add(descriptor); return(collection); }
private static IServiceCollection Add( PollyServiceCollection collection, Type serviceType, Type implementationType, ServiceLifetime lifetime) { var descriptor = new ServiceDescriptor(serviceType, implementationType, lifetime); collection.Add(descriptor); return(collection); }