Asp.net 在unity配置部分使用通用生命周期管理器
我有以下通用的生命周期管理器Asp.net 在unity配置部分使用通用生命周期管理器,asp.net,configuration,unity-container,lifetime,Asp.net,Configuration,Unity Container,Lifetime,我有以下通用的生命周期管理器 public class RequestLifetimeManager<T> : LifetimeManager, IDisposable { public override object GetValue() { return HttpContext.Current.Items[typeof(T).AssemblyQualifiedName]; } public override void
public class RequestLifetimeManager<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();
}
}
<types>
<type type="[interface]" mapTo="[concretetype]" >
<lifetime type="requestLifeTimeManager`1" />
</type>
</types>
如何引用泛型生存期管理器?引用泛型类型时不能使用类型别名,必须显式引用类型。下面的代码现在起作用了
<container name="defaultContainer">
<types>
<type type="ILayoutManager" mapTo="LayoutManager" >
<lifetime type="Publishing.UI.Common.Unity.RequestLifetimeManager`1[[Publishing.BLL.Managers.LayoutManager, Publishing.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c02010e20f60e4d2]], Publishing.UI.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c02010e20f60e4d2" />
</type>
</types>
</container>
Cannot create an instance of UI.Common.Unity.RequestLifetimeManager`1[T] because Type.ContainsGenericParameters is true.
<container name="defaultContainer">
<types>
<type type="ILayoutManager" mapTo="LayoutManager" >
<lifetime type="Publishing.UI.Common.Unity.RequestLifetimeManager`1[[Publishing.BLL.Managers.LayoutManager, Publishing.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c02010e20f60e4d2]], Publishing.UI.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c02010e20f60e4d2" />
</type>
</types>
</container>