3

我有以下通用生命周期管理器

    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. 

您如何引用通用生命周期管理器?

4

1 回答 1

4

引用泛型类型时不能使用类型别名,必须显式引用类型。以下现在有效

    <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>
于 2010-04-28T08:25:40.887 回答