C# Класс Microsoft.Practices.Unity.PerRequestLifetimeManager

A LifetimeManager that holds onto the instance given to it during the lifetime of a single HTTP request. This lifetime manager enables you to create instances of registered types that behave like singletons within the scope of an HTTP request. See remarks for important usage information.

Although the PerRequestLifetimeManager lifetime manager works correctly and can help in working with stateful or thread-unsafe dependencies within the scope of an HTTP request, it is generally not a good idea to use it when it can be avoided, as it can often lead to bad practices or hard to find bugs in the end-user's application code when used incorrectly. It is recommended that the dependencies you register are stateless and if there is a need to share common state between several objects during the lifetime of an HTTP request, then you can have a stateless service that explicitly stores and retrieves this state using the System.Web.HttpContext.Items collection of the System.Web.HttpContext.Current object.

For the instance of the registered type to be disposed automatically when the HTTP request completes, make sure to register the UnityPerRequestHttpModule with the web application. To do this, invoke the following in the Unity bootstrapping class (typically UnityMvcActivator.cs): DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));

Наследование: LifetimeManager
Показать файл Открыть проект

Открытые методы

Метод Описание
GetValue ( ) : object

Retrieves a value from the backing store associated with this lifetime policy.

RemoveValue ( ) : void

Removes the given object from the backing store.

SetValue ( object newValue ) : void

Stores the given value into the backing store for retrieval later.

Описание методов

GetValue() публичный Метод

Retrieves a value from the backing store associated with this lifetime policy.
public GetValue ( ) : object
Результат object

RemoveValue() публичный Метод

Removes the given object from the backing store.
public RemoveValue ( ) : void
Результат void

SetValue() публичный Метод

Stores the given value into the backing store for retrieval later.
public SetValue ( object newValue ) : void
newValue object The object being stored.
Результат void