ContainerRegisterSingletonTService, TImplementation Method

Simple Injector
Registers that the same a single instance of type TImplementation will be returned every time an TService type is requested. If TService and TImplementation represent the same type, the type is registered by itself. TImplementation must be thread-safe when working in a multi-threaded environment. If TImplementation implements IDisposable, a created instance will get disposed when Container.Dispose gets called.

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

public void RegisterSingleton<TService, TImplementation>()
where TService : class
where TImplementation : class, TService

Type Parameters

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

InvalidOperationException Thrown when this container instance is locked and can not be altered, or when the TService has already been registered.
ArgumentExceptionThrown when the given TImplementation type is not a type that can be created by the container.
See Also