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: 5.3.0
Syntax
Parameters
- serviceType
- Type: SystemType
The base type or interface to register. This can be an open-generic type. - implementationType
- Type: SystemType
The actual type that will be returned when requested. This can be an open-generic type.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | Thrown when either serviceType or implementationType are null references. |
ArgumentException | Thrown 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