ContainerRegisterConditional Method (Type, Type, PredicatePredicateContext)

Simple Injector
Conditionally registers that a new instance of implementationType will be returned every time a serviceType is requested (transient) and where the supplied predicate returns true. 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(
	Type serviceType,
	Type implementationType,
	Predicate<PredicateContext> predicate
)

Parameters

serviceType
Type: SystemType
The base type or interface to register. This can be an open-generic type.
implementationType
Type: SystemType
The actual type that will be returned when requested.
predicate
Type: SystemPredicatePredicateContext
The predicate that determines whether the implementationType 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.
Exceptions

ExceptionCondition
ArgumentNullExceptionThrown 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.
Remarks

This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient.
See Also

Reference