ContainerRegisterTService Method (FuncTService)

Simple Injector
Registers the specified delegate that allows returning transient instances of TService. The delegate is expected to always return a new instance on each call.

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

public void Register<TService>(
	Func<TService> instanceCreator
)
where TService : class

Parameters

instanceCreator
Type: SystemFuncTService
The delegate that allows building or creating new instances.

Type Parameters

TService
The interface or base type that can be used to retrieve instances.
Exceptions

ExceptionCondition
InvalidOperationException Thrown when this container instance is locked and can not be altered, or when the TService has already been registered.
ArgumentNullException Thrown when instanceCreator is a null reference.
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