3
我定义我的DbConntextObjDbContext Unity不会调用HttpContextLifetimeManager.RemoveValue()坏事?
_container.RegisterType<IDbConntextObj, DbConntextObj>(new HttpContextLifetimeManager<DbConntextObj>());
团结未在lifetimemanager
调用RemoveValue()我有一个的DbContext的多个存储库。
我lifetimemanager看起来是这样的:
public class HttpContextLifetimeManager<T> : LifetimeManager, IDisposable
{
private readonly string _itemName = typeof(T).AssemblyQualifiedName;
public override object GetValue()
{
return HttpContext.Current.Items[_itemName];
}
public override void RemoveValue()
{
var disposable = GetValue() as IDisposable;
HttpContext.Current.Items.Remove(_itemName);
if (disposable != null)
disposable.Dispose();
}
public override void SetValue(object newValue)
{
HttpContext.Current.Items[_itemName] = newValue;
}
public void Dispose()
{
RemoveValue();
}
}
这是个坏事的DbContext处置不会被调用? 对于Unity和MVC3有没有解决方法?