2010-04-28 2 views
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

제네릭 형식을 참조 할 때 형식 별칭을 사용할 수 없으므로 형식을 명시 적으로 참조해야합니다. 다음은 이제 작동합니다.

<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> 
관련 문제