WebRequestLifestyle Class

Simple Injector
Defines a lifestyle that caches instances during the execution of a single HTTP Web Request. Unless explicitly stated otherwise, instances created by this lifestyle will be disposed at the end of the web request.
Inheritance Hierarchy

SystemObject
  SimpleInjectorLifestyle
    SimpleInjectorScopedLifestyle
      SimpleInjector.Integration.WebWebRequestLifestyle

Namespace:  SimpleInjector.Integration.Web
Assembly:  SimpleInjector.Integration.Web (in SimpleInjector.Integration.Web.dll) Version: 4.10.2
Syntax

public sealed class WebRequestLifestyle : ScopedLifestyle

The WebRequestLifestyle type exposes the following members.

Constructors

  NameDescription
Public methodWebRequestLifestyle
Initializes a new instance of the WebRequestLifestyle class. The instance will ensure that created and cached instance will be disposed after the execution of the web request ended and when the created object implements IDisposable.
Public methodWebRequestLifestyle(Boolean) Obsolete.
Initializes a new instance of the WebRequestLifestyle class.
Top
Properties

  NameDescription
Public propertyLength
Gets the length of the lifestyle.
(Inherited from ScopedLifestyle.)
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.
(Overrides ScopedLifestyleCreateCurrentScopeProvider(Container).)
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 methodCreateRegistration(Type, Type, Container) Obsolete.
This overload has been deprecated. Please call CreateRegistration(Type, Container) instead.
(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 methodCreateRegistrationCoreTConcrete(Container)
Creates a new Registration instance defining the creation of the specified TConcrete with the caching as specified by this lifestyle.
(Inherited from ScopedLifestyle.)
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)
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 ScopedLifestyle.)
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.
(Inherited from ScopedLifestyle.)
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.
(Overrides ScopedLifestyleGetCurrentScopeCore(Container).)
Public methodRegisterForDisposal
Adds the disposable to the list of items that will get disposed when the scope ends.
(Inherited from ScopedLifestyle.)
Public methodStatic memberWhenCurrentRequestEnds Obsolete.
Allows registering an action delegate that will be called when the scope ends, but before the scope disposes any instances.
Public methodWhenScopeEnds
Allows registering an action delegate that will be called when the scope ends, but before the scope disposes any instances.
(Inherited from ScopedLifestyle.)
Top
Examples

The following example shows the usage of the WebRequestLifestyle class:
C#
var container = new Container();
container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(Lifestyle.Scoped);
See Also

Reference