컨텍스트 바인딩을 시도하지만 생성자 인수로 구체적인 구현 인터페이스를 바인딩 할 수 없습니다. Ninject에 버전은 다음 3.2.0.0생성자 인수로 여러 구체 구현에 바인드 인터페이스
내 구조이므로 :
INotifier에게 1. 2. XNotifier YNotifier
IPublisher을 1. 2. APublisher BPublisher
XNotifier로서 YNotifier는 IPublisher 유형의 생성자 인수를 취합니다. 여기
은 구속력이 내가 가진 :Bind<INotifier>()
.To<XNotifier>()
.When(x => notifictionControl.ToLower() == "xnotification")
.WithConstructorArgument("Publisher",ctx=>Kernel.Get<IPublisher>());
Bind<INotifier>()
.To<YNotifier>()
.When(x => notifictionControl.ToLower() == "ynotification")
.WithConstructorArgument("Publisher", ctx => Kernel.Get<IPublisher>());
사용법 : INotifier 일치하는 바인딩을 사용할 수 없으며, 활성화
오류 :
IParameter parameter = new ConstructorArgument("Publisher", publisher);
var notifier = kernel.Get<INotifier>(parameter);
그러나 점점 오류 다음 유형은 자기 구속력이 없습니다.
왜''을 받기에 매개 변수를 전달합니까? –
MaKCbIMKo
@MaKCbIMKo : INotifier를 구현 한 클래스의 생성자는 IPublisher의 구체적 구현을 기대합니다. – AnandSonake
하지만 바인딩에 생성자 인수가 이미 지정되어 있습니다. 왜 다시 할 수 있니? – MaKCbIMKo