我正在使用 Unity 注入上下文并使用以下生命周期管理器...
public class HttpContextLifetimeManager<T> : LifetimeManager, IDisposable
{
#region IDisposable Members
public void Dispose()
{
RemoveValue();
}
#endregion
public override object GetValue()
{
object value = HttpContext.Current.Items[typeof (T).AssemblyQualifiedName];
return value;
}
public override void RemoveValue()
{
HttpContext.Current.Items.Remove(typeof (T).AssemblyQualifiedName);
}
public override void SetValue(object newValue)
{
HttpContext.Current.Items[typeof (T).AssemblyQualifiedName]
= newValue;
}
}
- 第一个请求到第一页:显示值。
- 对第二页的第一个 Web 请求:更新值。
- 对第一页的第二个 Web 请求:显示旧值。
- 对第二页的第二个 Web 请求:显示新值。
我必须重新启动 VS 开发服务器才能让第一页显示新值。
那么上下文a)如何存在于页面请求之间并且b)特定于页面?