Conditionally registers that an instance of the type returned from implementationTypeFactory will be returned every time a serviceType is requested and where the supplied predicate returns true. The instance is cached according to the supplied lifestyle. Both the predicate and implementationTypeFactory will only be evaluated a finite number of times; they unsuited for making decisions based on runtime conditions.
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 4.0.0
public void RegisterConditional( Type serviceType, Func<TypeFactoryContext, Type> implementationTypeFactory, Lifestyle lifestyle, Predicate<PredicateContext> predicate )
Public Sub RegisterConditional ( serviceType As Type, implementationTypeFactory As Func(Of TypeFactoryContext, Type), lifestyle As Lifestyle, predicate As Predicate(Of PredicateContext) )
- Type: SystemType
The base type or interface to register. This can be an open-generic type.
- Type: SystemFuncTypeFactoryContext, Type
A factory that allows building Type objects that define the implementation type to inject, based on the given contextual information. The delegate is allowed to return (partially) open-generic types.
- Type: SimpleInjectorLifestyle
The lifestyle that defines how returned instances are cached.
- Type: SystemPredicatePredicateContext
The predicate that determines whether the registration can be applied for the requested service type. This predicate can be used to build a fallback mechanism where multiple registrations for the same service type are made.
|ArgumentNullException||Thrown when one of the arguments is a null reference (Nothing in VB).|
|ArgumentException||Thrown when serviceType is a partially-closed generic type.|
|InvalidOperationException||Thrown when this container instance is locked and can not be altered.|