ScopedLifestyle Class

Simple Injector
Base class for scoped lifestyles. A scoped lifestyle caches instances for the duration of an implicitly or explicitly defined scope. Such scope can be an (implicitly defined) web request or an explicitly defined Lifetime Scope. The lifetime of instances registered with a scoped lifestyle is always equal or bigger than one-instance-per-object-graph. In other words, a call to GetInstance() will never create more than one instance of such registered type.
Inheritance Hierarchy

SystemObject
  SimpleInjectorLifestyle
    SimpleInjectorScopedLifestyle
      SimpleInjector.LifestylesAsyncScopedLifestyle
      SimpleInjector.LifestylesThreadScopedLifestyle

Namespace:  SimpleInjector
Assembly:  SimpleInjector (in SimpleInjector.dll) Version: 5.3.0
Syntax

public abstract class ScopedLifestyle : Lifestyle

The ScopedLifestyle type exposes the following members.

Constructors

  NameDescription
Protected methodScopedLifestyle
Initializes a new instance of the ScopedLifestyle class.
Top
Properties

  NameDescription
Public propertyLength
Gets the length of the lifestyle. Implementers must implement this property. The diagnostic services use this value to compare lifestyles with each other to determine lifestyle misconfigurations.
(Overrides LifestyleLength.)
Public propertyName
Gets the user friendly name of this lifestyle.
(Inherited from Lifestyle.)
Top
Methods

  NameDescription
Protected methodCreateCurrentScopeProvider
Creates a delegate that upon invocation return the current Scope for this lifestyle and the given container, or null when the delegate is executed outside the context of such scope.
Public methodCreateProducer(Type, Type, Container)
Creates a new InstanceProducer instance for the given serviceType that will create new instances of specified implementationType with the caching as specified by this lifestyle.
(Inherited from Lifestyle.)
Public methodCreateProducerTService(FuncTService, Container)
Creates a new InstanceProducer instance for the given TService that will create new instances instance using the supplied instanceCreator with the caching as specified by this lifestyle.
(Inherited from Lifestyle.)
Public methodCreateProducerTService(Type, Container)
Creates a new InstanceProducer instance for the given TService that will create new instances of specified implementationType caching as specified by this lifestyle.
(Inherited from Lifestyle.)
Public methodCreateProducerTService, TImplementation(Container)
Creates a new InstanceProducer instance for the given TService that will create new instances of specified TImplementation with the caching as specified by this lifestyle.
(Inherited from Lifestyle.)
Public methodCreateRegistration(Type, Container)
Creates a new Registration instance defining the creation of the specified concreteType with the caching as specified by this lifestyle, or returns an already created Registration instance for this container + lifestyle + type combination. This method might fail when run in a partial trust sandbox when concreteType is an internal type.
(Inherited from Lifestyle.)
Public methodCreateRegistration(Type, FuncObject, Container)
Creates a new Registration instance defining the creation of the specified serviceType using the supplied instanceCreator with the caching as specified by this lifestyle.
(Inherited from Lifestyle.)
Public methodCreateRegistrationTConcrete(Container)
Creates a new Registration instance defining the creation of the specified TConcrete with the caching as specified by this lifestyle, or returns an already created Registration instance for this container + lifestyle + type combination.
(Inherited from Lifestyle.)
Public methodCreateRegistrationTService(FuncTService, Container)
Creates a new Registration instance defining the creation of the specified TService using the supplied instanceCreator with the caching as specified by this lifestyle.
(Inherited from Lifestyle.)
Protected methodCreateRegistrationCore(Type, Container)
When overridden in a derived class, creates a new Registration instance defining the creation of the specified concreteType with the caching as specified by this lifestyle.
(Overrides LifestyleCreateRegistrationCore(Type, Container).)
Protected methodCreateRegistrationCoreTService(FuncTService, Container)
When overridden in a derived class, creates a new Registration instance defining the creation of the specified TService using the supplied instanceCreator with the caching as specified by this lifestyle.
(Inherited from Lifestyle.)
Protected methodCreateRegistrationCoreTService(FuncTService, Container)
When overridden in a derived class, creates a new Registration instance defining the creation of the specified TService using the supplied instanceCreator with the caching as specified by this lifestyle.
(Overrides LifestyleCreateRegistrationCoreTService(FuncTService, Container).)
Public methodGetCurrentScope
Returns the current Scope for this lifestyle and the given container, or null when this method is executed outside the context of a scope.
Protected methodGetCurrentScopeCore
Returns the current Scope for this lifestyle and the given container, or null when this method is executed outside the context of a scope.
Public methodRegisterForDisposal
Adds the disposable to the list of items that will get disposed when the scope ends.
Public methodSetCurrentScope
Sets the given scope as current scope in the given context. An existing scope will be overridden and not disposed of. If the overridden scope must be disposed of, this must be done manually.
Protected methodSetCurrentScopeCore
Sets the given scope as current scope in the given context.
Public methodWhenScopeEnds
Allows registering an action delegate that will be called when the scope ends, but before the scope disposes any instances.
Top
Fields

  NameDescription
Public fieldStatic memberFlowing
Gets the scoped lifestyle that allows Scoped registrations to be resolved direclty from the Scope by calling GetInstanceTService. This allows multiple scopes to be active and overlap within the same logical context, such as a single thread, or an asynchronous context.
Top
See Also

Reference