Class ServiceCollectionExtensions
IServiceCollection extension methods.
[SuppressType]
public static class ServiceCollectionExtensions
- Inheritance
-
ServiceCollectionExtensions
- Inherited Members
Methods
AddIf(IServiceCollection, bool, Action<IServiceCollection>)
Executes the specified action if the specified condition
is true
which can be
used to conditionally configure the MVC services.
public static IServiceCollection AddIf(this IServiceCollection services, bool condition, Action<IServiceCollection> action)
Parameters
services
IServiceCollectionThe services collection.
condition
boolIf set to
true
the action is executed.action
Action<IServiceCollection>The action used to configure the MVC services.
Returns
- IServiceCollection
The same services collection.
AddIfElse(IServiceCollection, bool, Action<IServiceCollection>, Action<IServiceCollection>)
Executes the specified ifAction
if the specified condition
is
true
, otherwise executes the elseAction
. This can be used to conditionally
configure the MVC services.
public static IServiceCollection AddIfElse(this IServiceCollection services, bool condition, Action<IServiceCollection> ifAction, Action<IServiceCollection> elseAction)
Parameters
services
IServiceCollectionThe services collection.
condition
boolIf set to
true
theifAction
is executed, otherwise theelseAction
is executed.ifAction
Action<IServiceCollection>The action used to configure the MVC services if the condition is
true
.elseAction
Action<IServiceCollection>The action used to configure the MVC services if the condition is
false
.
Returns
- IServiceCollection
The same services collection.
AllowLazy(IServiceCollection)
注册允许延迟加载的服务
public static IServiceCollection AllowLazy(this IServiceCollection services)
Parameters
services
IServiceCollection
Returns
ConfigureAndValidateSingleton<TOptions>(IServiceCollection, IConfiguration)
Registers IOptions<TOptions> and TOptions
to the services container.
Also runs data annotation validation on application startup.
public static IServiceCollection ConfigureAndValidateSingleton<TOptions>(this IServiceCollection services, IConfiguration configuration) where TOptions : class
Parameters
services
IServiceCollectionThe services collection.
configuration
IConfigurationThe configuration.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptions
The type of the options.
ConfigureAndValidateSingleton<TOptions>(IServiceCollection, IConfiguration, Action<BinderOptions>)
Registers IOptions<TOptions> and TOptions
to the services container.
Also runs data annotation validation on application startup.
public static IServiceCollection ConfigureAndValidateSingleton<TOptions>(this IServiceCollection services, IConfiguration configuration, Action<BinderOptions> configureBinder) where TOptions : class
Parameters
services
IServiceCollectionThe services collection.
configuration
IConfigurationThe configuration.
configureBinder
Action<BinderOptions>Used to configure the binder options.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptions
The type of the options.
ConfigureAndValidateSingleton<TOptions>(IServiceCollection, IConfiguration, Func<TOptions, bool>)
Registers IOptions<TOptions> and TOptions
to the services container.
Also runs data annotation validation and custom validation using the default failure message on application startup.
public static IServiceCollection ConfigureAndValidateSingleton<TOptions>(this IServiceCollection services, IConfiguration configuration, Func<TOptions, bool> validation) where TOptions : class
Parameters
services
IServiceCollectionThe services collection.
configuration
IConfigurationThe configuration.
validation
Func<TOptions, bool>The validation function.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptions
The type of the options.
ConfigureAndValidateSingleton<TOptions>(IServiceCollection, IConfiguration, Func<TOptions, bool>, Action<BinderOptions>)
Registers IOptions<TOptions> and TOptions
to the services container.
Also runs data annotation validation and custom validation using the default failure message on application startup.
public static IServiceCollection ConfigureAndValidateSingleton<TOptions>(this IServiceCollection services, IConfiguration configuration, Func<TOptions, bool> validation, Action<BinderOptions> configureBinder) where TOptions : class
Parameters
services
IServiceCollectionThe services collection.
configuration
IConfigurationThe configuration.
validation
Func<TOptions, bool>The validation function.
configureBinder
Action<BinderOptions>Used to configure the binder options.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptions
The type of the options.
ConfigureAndValidateSingleton<TOptions>(IServiceCollection, IConfiguration, Func<TOptions, bool>, string)
Registers IOptions<TOptions> and TOptions
to the services container.
Also runs data annotation validation and custom validation on application startup.
public static IServiceCollection ConfigureAndValidateSingleton<TOptions>(this IServiceCollection services, IConfiguration configuration, Func<TOptions, bool> validation, string failureMessage) where TOptions : class
Parameters
services
IServiceCollectionThe services collection.
configuration
IConfigurationThe configuration.
validation
Func<TOptions, bool>The validation function.
failureMessage
stringThe failure message to use when validation fails.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptions
The type of the options.
ConfigureAndValidateSingleton<TOptions>(IServiceCollection, IConfiguration, Func<TOptions, bool>, string, Action<BinderOptions>)
Registers IOptions<TOptions> and TOptions
to the services container.
Also runs data annotation validation and custom validation on application startup.
public static IServiceCollection ConfigureAndValidateSingleton<TOptions>(this IServiceCollection services, IConfiguration configuration, Func<TOptions, bool> validation, string failureMessage, Action<BinderOptions> configureBinder) where TOptions : class
Parameters
services
IServiceCollectionThe services collection.
configuration
IConfigurationThe configuration.
validation
Func<TOptions, bool>The validation function.
failureMessage
stringThe failure message to use when validation fails.
configureBinder
Action<BinderOptions>Used to configure the binder options.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptions
The type of the options.
ConfigureSingleton<TOptions>(IServiceCollection, IConfiguration)
Registers IOptions<TOptions> and TOptions
to the services container.
public static IServiceCollection ConfigureSingleton<TOptions>(this IServiceCollection services, IConfiguration configuration) where TOptions : class
Parameters
services
IServiceCollectionThe services collection.
configuration
IConfigurationThe configuration.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptions
The type of the options.
ConfigureSingleton<TOptions>(IServiceCollection, IConfiguration, Action<BinderOptions>)
Registers IOptions<TOptions> and TOptions
to the services container.
public static IServiceCollection ConfigureSingleton<TOptions>(this IServiceCollection services, IConfiguration configuration, Action<BinderOptions> configureBinder) where TOptions : class
Parameters
services
IServiceCollectionThe services collection.
configuration
IConfigurationThe configuration.
configureBinder
Action<BinderOptions>Used to configure the binder options.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptions
The type of the options.
Decorate<TService, TImpl>(IServiceCollection, params object[])
装饰服务,TImpl
必须有一个构造函数接受TService
类型的参数
public static bool Decorate<TService, TImpl>(this IServiceCollection services, params object[] parameters)
Parameters
services
IServiceCollectionparameters
object[]
Returns
Type Parameters
TService
TImpl