Registers the specified delegate that allows constructing a single instance of TService. This delegate will be called at most once during the lifetime of the application. The returned instance must be thread-safe when working in a multi-threaded environment. If the instance returned from instanceCreator implements IDisposable, the created instance will get disposed when Container.Dispose gets called.
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 4.6.0
public void RegisterSingleton<TService>( Func<TService> instanceCreator ) where TService : class
Public Sub RegisterSingleton(Of TService As Class) ( instanceCreator As Func(Of TService) )
- Type: SystemFunc
The delegate that allows building or creating this single instance.
- The interface or base type that can be used to retrieve instances.
|InvalidOperationException||Thrown when this container instance is locked and can not be altered, or when a instanceCreator for TService has already been registered.|
|ArgumentNullException||Thrown when instanceCreator is a null reference.|