Note: This API is now obsolete.
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 the overload that accepts a FuncTResult delegate.
Namespace: SimpleInjector
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 5.3.0
Syntax
[ObsoleteAttribute("Please use RegisterInstance<TService>(TService) instead. Will be removed in version 6.0.", true)] [EditorBrowsableAttribute(EditorBrowsableState.Never)] public void RegisterSingleton<TService>( TService instance ) where TService : class
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