Note: This API is now obsolete.
Defines a lifestyle that caches instances during the execution of a single ASP.NET Request.
Unless explicitly stated otherwise, instances created by this lifestyle will be disposed at the end
of the request. Do note that this lifestyle requires the
UseSimpleInjectorAspNetRequestScoping.
to be registered in the Web API configuration.
Inheritance Hierarchy
SimpleInjectorLifestyle
SimpleInjectorScopedLifestyle
SimpleInjector.LifestylesAsyncScopedLifestyle
SimpleInjector.Integration.AspNetCoreAspNetRequestLifestyle
Namespace: SimpleInjector.Integration.AspNetCore
Assembly: SimpleInjector.Integration.AspNetCore (in SimpleInjector.Integration.AspNetCore.dll) Version: 4.10.3
Syntax
[ObsoleteAttribute("Please use SimpleInjector.Lifestyles.AsyncScopedLifestyle instead. Will be removed in version 5.0.", true)] public sealed class AspNetRequestLifestyle : AsyncScopedLifestyle
The AspNetRequestLifestyle type exposes the following members.
Constructors
Name | Description | |
---|---|---|
AspNetRequestLifestyle | Initializes a new instance of the AspNetRequestLifestyle class.
The created and cached instance will be disposed when the Web API request ends, and when the
created object implements IDisposable.
| |
AspNetRequestLifestyle(Boolean) | Obsolete. Initializes a new instance of the AspNetRequestLifestyle class. |
Properties
Name | Description | |
---|---|---|
Length | Gets the length of the lifestyle. (Inherited from ScopedLifestyle.) | |
Name | Gets the user friendly name of this lifestyle. (Inherited from Lifestyle.) |
Methods
Name | Description | |
---|---|---|
CreateCurrentScopeProvider |
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.
(Inherited from AsyncScopedLifestyle.) | |
CreateProducer(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.) | |
CreateProducerTService(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.) | |
CreateProducerTService(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.) | |
CreateProducerTService, 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.) | |
CreateRegistration(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.) | |
CreateRegistration(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.) | |
CreateRegistration(Type, Type, Container) | Obsolete.
This overload has been deprecated. Please call CreateRegistration(Type, Container)
instead.
(Inherited from Lifestyle.) | |
CreateRegistrationTConcrete(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.) | |
CreateRegistrationTService(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.) | |
CreateRegistrationCoreTConcrete(Container) |
Creates a new Registration instance defining the creation of the
specified TConcrete with the caching as specified by this lifestyle.
(Inherited from ScopedLifestyle.) | |
CreateRegistrationCoreTService(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.) | |
CreateRegistrationCoreTService(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.) | |
GetCurrentScope |
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.) | |
GetCurrentScopeCore |
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 AsyncScopedLifestyle.) | |
RegisterForDisposal |
Adds the disposable to the list of items that will get disposed when the
scope ends.
(Inherited from ScopedLifestyle.) | |
WhenScopeEnds |
Allows registering an action delegate that will be called when the scope ends,
but before the scope disposes any instances.
(Inherited from ScopedLifestyle.) |
Examples
C#
var container = new Container(); container.Options.DefaultScopedLifestyle = new AspNetRequestLifestyle(); container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(Lifestyle.Scoped);
See Also