약간 혼란스러운 Unity를 사용하는 시나리오가 있습니다 ... 사용자를 인증하는 AuthenticationService가 있고 TextLogger 클래스 나 DbLogger 클래스를 사용하여 텍스트 파일이나 데이터베이스에 성공적으로 로그 할 때가 있습니다. 일반적으로 이는 이제까지 클래스 내 프로젝트 나는 아래로 내 모듈 클래스에 적절하게 등록 할에 사용됩니다Microsoft Unity, 두 가지 유사한 종속성을 해결 하시겠습니까?
public class LoggingModule
{
IUnityContainer _iocContainer;
public LoggingModule(IUnityContainer container)
{
_iocContainer = container;
}
public void Init()
{
//Add any logic here to look in a config file, check a property
//or any other condition to decide which implementation is registered.
//register the database logger to the ILogger interface
_iocContainer.RegisterType(typeof(ILogger), typeof(DBLogger));
}
}
그리고 이것은 내 인증 서비스의 생성자에 주입됩니다. 그러나 응용 프로그램의 여러 지점에서 두 로거를 모두 사용하려면 먼저 Init 메서드에서 두 유형을 모두 등록해야합니다 (예 : TextLogger 및 DBLogger). 둘째, 내 컨테이너가 해결할 유형을 어떻게 알 수 있습니까?
도와주세요
....
http://stackoverflow.com/questions/6109404/how-to-register-multiple-types-that-implement-the-same-interface – adt