ContainerRegisterTService Method (FuncTService, Lifestyle)

Simple Injector
Registers the specified delegate instanceCreator that will produce instances of type TService and will be returned when an instance of type TService is requested. The delegate is expected to produce new instances on each call. The instances are cached according to the supplied lifestyle.

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

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

Parameters

instanceCreator
Type: SystemFuncTService
The delegate that allows building or creating new instances.
lifestyle
Type: SimpleInjectorLifestyle
The lifestyle that specifies how the returned instance will be cached.

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 one of the supplied arguments is a null reference (Nothing in VB).
See Also

Reference