ContainerRegisterConditionalTService, TImplementation Method (Lifestyle, PredicatePredicateContext)

Simple Injector
Conditionally registers that an instance of TImplementation will be returned every time a TService is requested and where the supplied predicate returns true. The instance is cached according to the supplied lifestyle. The predicate will only be evaluated a finite number of times; the predicate is unsuited for making decisions based on runtime conditions.

Namespace:  SimpleInjector
Assembly:  SimpleInjector (in SimpleInjector.dll) Version: 4.0.0
Syntax

public void RegisterConditional<TService, TImplementation>(
	Lifestyle lifestyle,
	Predicate<PredicateContext> predicate
)
where TService : class
where TImplementation : class, TService

Parameters

lifestyle
Type: SimpleInjectorLifestyle
The lifestyle that specifies how the returned instance will be cached.
predicate
Type: SystemPredicatePredicateContext
The predicate that determines whether the TImplementation 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.

Type Parameters

TService
The interface or base type that can be used to retrieve the instances.
TImplementation
The concrete type that will be registered.
Exceptions

ExceptionCondition
ArgumentNullException Thrown when one of the arguments is a null reference (Nothing in VB).
InvalidOperationException Thrown when this container instance is locked and can not be altered.
See Also

Reference