I am trying to do contextual binding but not able to bind concrete implementation interface as constructor argument. Ninject version: 3.2.0.0
My structure is as follows:
INotifier 1. XNotifier 2. YNotifier
IPublisher 1. APublisher 2. BPublisher
where as XNotifier and YNotifier takes constructor argument of type IPublisher.
Here is the binding I have:
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>());
Usage:
IParameter parameter = new ConstructorArgument("Publisher", publisher);
var notifier = kernel.Get<INotifier>(parameter);
But getting following error:
Error activating INotifier No matching bindings are available, and the type is not self-bindable.