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.
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 4.0.0
public void RegisterSingleton<TService>( TService instance ) where TService : class
Public Sub RegisterSingleton(Of TService As Class) ( instance As TService )
The instance to register.
- The interface or base type that can be used to retrieve the instance.
|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.|