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>).
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 5.3.0
public void RegisterInstance<TService>( TService instance ) where TService : class
Public Sub RegisterInstance(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.|