LifestyleSingleton Field

Simple Injector

The lifestyle that caches components during the lifetime of the Container instance and guarantees that only a single instance of that component is created for that instance. Since general use is to create a single Container instance for the lifetime of the application / AppDomain, this would mean that only a single instance of that component would exist during the lifetime of the application. In a multi-threaded applications, implementations registered using this lifestyle must be thread-safe.

In case the type of a cached instance implements IDisposable, the container will ensure its disposal when the container gets disposed.

Namespace:  SimpleInjector
Assembly:  SimpleInjector (in SimpleInjector.dll) Version: 4.0.0

public static readonly Lifestyle Singleton

Field Value

Type: Lifestyle

The following example registers the RealTimeProvider implementation for the ITimeProvider service type using the Singleton lifestyle:
var container = new Container();

container.Register<ITimeProvider, RealTimeProvider>(Lifestyle.Singleton);
See Also