/// <summary> /// Adds a scoped service of the type specified in <typeparamref name="TService"/> to the /// specified <see cref="IServiceCollection"/>. /// </summary> /// <typeparam name="TService">The type of the service to add.</typeparam> /// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <seealso cref="ServiceLifetime.Scoped"/> public static IServiceCollection AddScoped <TService>(this PollyServiceCollection services) where TService : class { if (services == null) { throw new ArgumentNullException(nameof(services)); } return(services.AddScoped(typeof(TService))); }
/// <summary> /// Adds a scoped service of the type specified in <paramref name="serviceType"/> 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 and the implementation to use. /// </param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <seealso cref="ServiceLifetime.Scoped"/> public static IServiceCollection AddScoped( this PollyServiceCollection services, Type serviceType) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (serviceType == null) { throw new ArgumentNullException(nameof(serviceType)); } return(services.AddScoped(serviceType, serviceType)); }
/// <summary> /// Adds a scoped service of the type specified in <typeparamref name="TService"/> with a /// factory specified in <paramref name="implementationFactory"/> to the specified <see cref="IServiceCollection"/>. /// </summary> /// <typeparam name="TService">The type of the service to add.</typeparam> /// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param> /// <param name="implementationFactory">The factory that creates the service.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <seealso cref="ServiceLifetime.Scoped"/> public static IServiceCollection AddScoped <TService>( this PollyServiceCollection services, Func <IServiceProvider, TService> implementationFactory) where TService : class { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (implementationFactory == null) { throw new ArgumentNullException(nameof(implementationFactory)); } return(services.AddScoped(typeof(TService), implementationFactory)); }