I'm looking at contextual binding with Ninject. This is for when you have multiple implementations of some abstraction, and context in the injection target class determines which of those implementations is injected.
In the documentation, the example using "named bindings" looks like this:
Bind<IWeapon>().To<Shuriken>().Named("Strong");
Bind<IWeapon>().To<Dagger>().Named("Weak");
class WeakAttack {
readonly IWeapon _weapon;
public WeakAttack([Named("Weak")] IWeapon weakWeapon){
_weapon = weakWeapon;
}
public void Attack(string victim){
Console.WriteLine(_weapon.Hit(victim));
}
}
That means that the assembly which contains WeakAttack
will obviously have to reference Ninject to use the NamedAttribute
in the constructor. The target of dependency injection should not have to know which DI container is used. What am I missing here?