在统一配置部分使用通用生命周期管理器
我有以下通用生命周期管理器
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();
}
}
如何在统一配置部分引用它。创建类型别名
<typeAlias alias="requestLifeTimeManager`1" type=" UI.Common.Unity.RequestLifetimeManager`1, UI.Common" />
并将其指定为生命周期管理器
<types>
<type type="[interface]" mapTo="[concretetype]" >
<lifetime type="requestLifeTimeManager`1" />
</type>
</types>
会导致以下错误
Cannot create an instance of UI.Common.Unity.RequestLifetimeManager`1[T] because Type.ContainsGenericParameters is true.
如何引用通用生命周期管理器?
I have the following generic lifetime manager
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();
}
}
How do I reference this in the unity config section. Creating a type alias
<typeAlias alias="requestLifeTimeManager`1" type=" UI.Common.Unity.RequestLifetimeManager`1, UI.Common" />
and specifying it as a lifetime manager
<types>
<type type="[interface]" mapTo="[concretetype]" >
<lifetime type="requestLifeTimeManager`1" />
</type>
</types>
causes the following error
Cannot create an instance of UI.Common.Unity.RequestLifetimeManager`1[T] because Type.ContainsGenericParameters is true.
How do you reference generic lifetime managers ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用泛型类型时不能使用类型别名,必须显式引用类型。现在可以使用以下内容
You cannot use the type aliases when referencing generic type, you have to reference the types explicitly. The following now works