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 に答える