ContainerRegisterSingleton Method (Type, Type)

Simple Injector
Registers that the same instance of type implementationType will be returned every time an instance of type serviceType type is requested. If serviceType and implementationType represent the same type, the type is registered by itself. implementationType must be thread-safe when working in a multi-threaded environment. Open and closed generic types are supported.

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

public void RegisterSingleton(
	Type serviceType,
	Type implementationType


Type: SystemType
The base type or interface to register. This can be an open-generic type.
Type: SystemType
The actual type that will be returned when requested. This can be an open-generic type.

ArgumentNullExceptionThrown when either serviceType or implementationType are null references (Nothing in VB).
ArgumentExceptionThrown when implementationType is no sub type from serviceType, or when one of them represents an open generic type.
InvalidOperationException Thrown when this container instance is locked and can not be altered, or when an the serviceType has already been registered.
See Also