I have a follow up question to this question: Is it possible to bind different interfaces to the same instance of a class implementing all of them?
I have a scenario where one of the interface needs to be resolved by the name provided by "Named" extension, and another doesn't need a name to be resolved.
For instance
public interface IMachine { }
public interface IDrillMachine : IMachine { }
public class Drill: IDrillMachine { }
public class ScrewDriver: IMachine { }
Ninject Binding
Bind<IMachine, IDrillMachine>().To<Drill>().Named("Drill");
Bind<IMachine>.To<ScrewDriver>().Named("ScrewDriver");
Injection
public class MachineConsumer
{
public MachineConsumer([Named("Drill")]IMachine drillMachine)
{ }
}
public class DrillConsumer
{
public DrillConsumer(IDrillMachine drillMachine)
{ }
}
My code isn't in working condition, so can't test. But I think that at the time of resolving IDrillMachine
there will be confusion, isn't it?