A HttpContextLifetimeManager to make Unity 2.0 work better with for example MVC.
public class HttpContextLifetimeManager<T> : LifetimeManager, IDisposable
{
public override object GetValue()
{
return HttpContext.Current.Items[typeof(T).AssemblyQualifiedName];
}
public override void RemoveValue()
{
HttpContext.Current.Items.Remove(typeof(T).AssemblyQualifiedName);
}
public override void SetValue(object newValue)
{
HttpContext.Current.Items[typeof(T).AssemblyQualifiedName] = newValue;
}
public void Dispose()
{
RemoveValue();
}
}
Fork
0 Feedback
You must log in before you can give any feedback
You must log in before you can post a comment


1.2k
0




Mark 'c#' tag as 'like'
Mark 'c#' tag as 'ignore'