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