ServiceCollectionServiceExtensions Class¶
Extension methods for adding services to an Microsoft.Extensions.DependencyInjection.IServiceCollection
.
- Namespace
Microsoft.Extensions.DependencyInjection
- Assemblies
- Microsoft.Extensions.DependencyInjection.Abstractions
Syntax¶
public class ServiceCollectionServiceExtensions
-
class
Microsoft.Extensions.DependencyInjection.
ServiceCollectionServiceExtensions
Methods¶
-
AddScoped
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type)¶ Adds a scoped service of the type specified in <em>serviceType</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register and the implementation to use.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddScoped(this IServiceCollection services, Type serviceType)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddScoped
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type, System.Func<System.IServiceProvider, System.Object>) Adds a scoped service of the type specified in <em>serviceType</em> with a factory specified in <em>implementationFactory</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register.
- implementationFactory (System.Func<System.IServiceProvider>) – The factory that creates the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddScoped(this IServiceCollection services, Type serviceType, Func<IServiceProvider, object> implementationFactory)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddScoped
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type, System.Type) Adds a scoped service of the type specified in <em>serviceType</em> with an implementation of the type specified in <em>implementationType</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register.
- implementationType (System.Type) – The implementation type of the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddScoped(this IServiceCollection services, Type serviceType, Type implementationType)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddScoped<TService>
(Microsoft.Extensions.DependencyInjection.IServiceCollection)¶ Adds a scoped service of the type specified in <em>TService</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to.Return type: Microsoft.Extensions.DependencyInjection.IServiceCollection Returns: A reference to this instance after the operation has completed. public static IServiceCollection AddScoped<TService>(this IServiceCollection services)where TService : class
-
AddScoped<TService>
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Func<System.IServiceProvider, TService>) Adds a scoped service of the type specified in <em>TService</em> with a factory specified in <em>implementationFactory</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - implementationFactory (System.Func<System.IServiceProvider<System.IServiceProvider>, TService>) – The factory that creates the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddScoped<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory)where TService : class
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddScoped<TService, TImplementation>
(Microsoft.Extensions.DependencyInjection.IServiceCollection)¶ Adds a scoped service of the type specified in <em>TService</em> with an implementation type specified in <em>TImplementation</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to.Return type: Microsoft.Extensions.DependencyInjection.IServiceCollection Returns: A reference to this instance after the operation has completed. public static IServiceCollection AddScoped<TService, TImplementation>(this IServiceCollection services)where TService : class where TImplementation : class, TService
-
AddScoped<TService, TImplementation>
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Func<System.IServiceProvider, TImplementation>) Adds a scoped service of the type specified in <em>TService</em> with an implementation type specified in <em>TImplementation</em> using the factory specified in <em>implementationFactory</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - implementationFactory (System.Func<System.IServiceProvider<System.IServiceProvider>, TImplementation>) – The factory that creates the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddScoped<TService, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory)where TService : class where TImplementation : class, TService
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddSingleton
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type)¶ Adds a singleton service of the type specified in <em>serviceType</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register and the implementation to use.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddSingleton
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type, System.Func<System.IServiceProvider, System.Object>) Adds a singleton service of the type specified in <em>serviceType</em> with a factory specified in <em>implementationFactory</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register.
- implementationFactory (System.Func<System.IServiceProvider>) – The factory that creates the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, Func<IServiceProvider, object> implementationFactory)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddSingleton
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type, System.Object) Adds a singleton service of the type specified in <em>serviceType</em> with an instance specified in <em>implementationInstance</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register.
- implementationInstance (System.Object) – The instance of the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, object implementationInstance)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddSingleton
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type, System.Type) Adds a singleton service of the type specified in <em>serviceType</em> with an implementation of the type specified in <em>implementationType</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register.
- implementationType (System.Type) – The implementation type of the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, Type implementationType)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddSingleton<TService>
(Microsoft.Extensions.DependencyInjection.IServiceCollection)¶ Adds a singleton service of the type specified in <em>TService</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to.Return type: Microsoft.Extensions.DependencyInjection.IServiceCollection Returns: A reference to this instance after the operation has completed. public static IServiceCollection AddSingleton<TService>(this IServiceCollection services)where TService : class
-
AddSingleton<TService>
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Func<System.IServiceProvider, TService>) Adds a singleton service of the type specified in <em>TService</em> with a factory specified in <em>implementationFactory</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - implementationFactory (System.Func<System.IServiceProvider<System.IServiceProvider>, TService>) – The factory that creates the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddSingleton<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory)where TService : class
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddSingleton<TService>
(Microsoft.Extensions.DependencyInjection.IServiceCollection, TService) Adds a singleton service of the type specified in <em>TService</em> with an instance specified in <em>implementationInstance</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - implementationInstance (TService) – The instance of the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddSingleton<TService>(this IServiceCollection services, TService implementationInstance)where TService : class
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddSingleton<TService, TImplementation>
(Microsoft.Extensions.DependencyInjection.IServiceCollection)¶ Adds a singleton service of the type specified in <em>TService</em> with an implementation type specified in <em>TImplementation</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to.Return type: Microsoft.Extensions.DependencyInjection.IServiceCollection Returns: A reference to this instance after the operation has completed. public static IServiceCollection AddSingleton<TService, TImplementation>(this IServiceCollection services)where TService : class where TImplementation : class, TService
-
AddSingleton<TService, TImplementation>
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Func<System.IServiceProvider, TImplementation>) Adds a singleton service of the type specified in <em>TService</em> with an implementation type specified in <em>TImplementation</em> using the factory specified in <em>implementationFactory</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - implementationFactory (System.Func<System.IServiceProvider<System.IServiceProvider>, TImplementation>) – The factory that creates the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddSingleton<TService, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory)where TService : class where TImplementation : class, TService
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddTransient
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type)¶ Adds a transient service of the type specified in <em>serviceType</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register and the implementation to use.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddTransient
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type, System.Func<System.IServiceProvider, System.Object>) Adds a transient service of the type specified in <em>serviceType</em> with a factory specified in <em>implementationFactory</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register.
- implementationFactory (System.Func<System.IServiceProvider>) – The factory that creates the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType, Func<IServiceProvider, object> implementationFactory)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddTransient
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Type, System.Type) Adds a transient service of the type specified in <em>serviceType</em> with an implementation of the type specified in <em>implementationType</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - serviceType (System.Type) – The type of the service to register.
- implementationType (System.Type) – The implementation type of the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType, Type implementationType)
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddTransient<TService>
(Microsoft.Extensions.DependencyInjection.IServiceCollection)¶ Adds a transient service of the type specified in <em>TService</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to.Return type: Microsoft.Extensions.DependencyInjection.IServiceCollection Returns: A reference to this instance after the operation has completed. public static IServiceCollection AddTransient<TService>(this IServiceCollection services)where TService : class
-
AddTransient<TService>
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Func<System.IServiceProvider, TService>) Adds a transient service of the type specified in <em>TService</em> with a factory specified in <em>implementationFactory</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - implementationFactory (System.Func<System.IServiceProvider<System.IServiceProvider>, TService>) – The factory that creates the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddTransient<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory)where TService : class
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-
AddTransient<TService, TImplementation>
(Microsoft.Extensions.DependencyInjection.IServiceCollection)¶ Adds a transient service of the type specified in <em>TService</em> with an implementation type specified in <em>TImplementation</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to.Return type: Microsoft.Extensions.DependencyInjection.IServiceCollection Returns: A reference to this instance after the operation has completed. public static IServiceCollection AddTransient<TService, TImplementation>(this IServiceCollection services)where TService : class where TImplementation : class, TService
-
AddTransient<TService, TImplementation>
(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Func<System.IServiceProvider, TImplementation>) Adds a transient service of the type specified in <em>TService</em> with an implementation type specified in <em>TImplementation</em> using the factory specified in <em>implementationFactory</em> to the specified
Microsoft.Extensions.DependencyInjection.IServiceCollection
.Arguments: - services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
Microsoft.Extensions.DependencyInjection.IServiceCollection
to add the service to. - implementationFactory (System.Func<System.IServiceProvider<System.IServiceProvider>, TImplementation>) – The factory that creates the service.
Return type: Returns: A reference to this instance after the operation has completed.
public static IServiceCollection AddTransient<TService, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory)where TService : class where TImplementation : class, TService
- services (Microsoft.Extensions.DependencyInjection.IServiceCollection) – The
-