Registers a single instance that will be returned when an instance of type
serviceType is requested. This instance must be thread-safe
when working in a multi-threaded environment.
NOTE: Do note that instances supplied by this method NEVER get disposed by the
container, since the instance is assumed to outlive this container instance. If disposing is
required, use
RegisterSingleton(Type, Func<object>).
Namespace: SimpleInjector
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 5.3.0
Syntax
Parameters
- serviceType
- Type: SystemType
The base type or interface to register. - instance
- Type: SystemObject
The instance to register.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | Thrown when either serviceType or instance are null references. |
ArgumentException | Thrown when instance is no sub type from serviceType. |
InvalidOperationException | Thrown when this container instance is locked and can not be altered, or when an the serviceType has already been registered. |
See Also