Registers a single instance that will be returned when an instance of type
TService 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<TService>(Func<TService>).
Namespace: SimpleInjector
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 5.3.0
Syntax
Parameters
- instance
- Type: TService
The instance to register.
Type Parameters
- TService
- The interface or base type that can be used to retrieve the instance.
Exceptions
Exception | Condition |
---|---|
InvalidOperationException | Thrown when this container instance is locked and can not be altered, or when the TService has already been registered. |
ArgumentNullException | Thrown when instance is a null reference. |
See Also