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
servicesIServiceCollectionThe services collection.
conditionboolIf set to
truethe action is executed.actionAction<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
servicesIServiceCollectionThe services collection.
conditionboolIf set to
truetheifActionis executed, otherwise theelseActionis executed.ifActionAction<IServiceCollection>The action used to configure the MVC services if the condition is
true.elseActionAction<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
servicesIServiceCollection
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
servicesIServiceCollectionThe services collection.
configurationIConfigurationThe configuration.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptionsThe 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
servicesIServiceCollectionThe services collection.
configurationIConfigurationThe configuration.
configureBinderAction<BinderOptions>Used to configure the binder options.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptionsThe 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
servicesIServiceCollectionThe services collection.
configurationIConfigurationThe configuration.
validationFunc<TOptions, bool>The validation function.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptionsThe 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
servicesIServiceCollectionThe services collection.
configurationIConfigurationThe configuration.
validationFunc<TOptions, bool>The validation function.
configureBinderAction<BinderOptions>Used to configure the binder options.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptionsThe 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
servicesIServiceCollectionThe services collection.
configurationIConfigurationThe configuration.
validationFunc<TOptions, bool>The validation function.
failureMessagestringThe failure message to use when validation fails.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptionsThe 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
servicesIServiceCollectionThe services collection.
configurationIConfigurationThe configuration.
validationFunc<TOptions, bool>The validation function.
failureMessagestringThe failure message to use when validation fails.
configureBinderAction<BinderOptions>Used to configure the binder options.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptionsThe 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
servicesIServiceCollectionThe services collection.
configurationIConfigurationThe configuration.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptionsThe 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
servicesIServiceCollectionThe services collection.
configurationIConfigurationThe configuration.
configureBinderAction<BinderOptions>Used to configure the binder options.
Returns
- IServiceCollection
The same services collection.
Type Parameters
TOptionsThe 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
servicesIServiceCollectionparametersobject[]
Returns
Type Parameters
TServiceTImpl