2

XML 설정 파일에서 사용자 정의 평생 생성자에 매개 변수를 전달 : 이제유니티 :이처럼 내 CustomLifetimeManager 썼다

public class CustomLifetimeManager <T> : LifetimeManager 
{ 
    private readonly string _arg; 

    public CustomLifetimeManager(string arg) 
    { 
     _arg = arg; 
    } 
} 

은 쉽게 프로그래밍 용기를 구성 작동하지만 다음과 같이 구성 파일에 어떻게 추가 ?

<type type="myTime" 
     mapTo="myImpl"> 
     <lifetime type="CustomLifetimeManager"/> 
</type> 
+0

설정을 읽으시겠습니까? 그렇다면 값이있는 키를 추가하고 다음과 같이 읽습니다. string configValue = System.Configuration.ConfigurationManager.type [ "keyName"]; – MrFox

+0

아니요, 전화를 걸어주세요 : unityConfigurationSection.Containers [0] .Configure (Container) 내 컨테이너를 구성합니다. 구성 파일에 수명 관리자를 구성하고 싶습니다. – onof

답변

0

TypeConverter를 추가해야합니다. 이 클래스는 문자열을 가져 와서 원하는 형식으로 변환합니다.

<register type="MyType" mapTo"MyImpl"> 
    <lifetime typeConverter="CustomLifetimeManagerConverter" value="arg" /> 
</register> 

을하고 거기에서 그냥 (다른 유형과 같은 형식 변환기를 찾을 수있는 설정을 가정) 작동합니다 : 당신이 그것을 구현 한 후에는 다음 설정 파일 같은 것을 할 수 있습니다.