ContainerRegisterSingletonTService Method (FuncTService)

Simple Injector
Registers the specified delegate that allows constructing a single instance of TService. This delegate will be called at most once during the lifetime of the application. The returned instance must be thread-safe when working in a multi-threaded environment. If the instance returned from instanceCreator implements IDisposable, the created instance will get disposed when Container.Dispose gets called.

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

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

Parameters

instanceCreator
Type: SystemFuncTService
The delegate that allows building or creating this single instance.

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 a instanceCreator for TService has already been registered.
ArgumentNullExceptionThrown when instanceCreator is a null reference.
See Also

Reference