How to have NInject follow type hierarchy?

47 Views Asked by At

I am surprised that NInject does not follow the type hierarchy when looking for a binding.

Bind<ICollection<ICard>>().ToConstructor(/* .. */);
var Cards = IoC.Kernel.Get<IList<ICard>>();

In the above code, the Kernel.Get<..>() sends me an ActivationException because I haven't explicitely bound IList<ICard>. In other words, for NInject, an IList<ICard> is not an ICollection<ICard>. Sounds strange to me.

Of course I can remove the error by explicitely adding Bind<IList<ICard>>().To<..>(), but I don't understand why NInject doesn't follow type hierarchy by default. Am I missing something?

So, can somebody explain:

  • Why NInject forces me to be that specific in my bindings
  • How I can overcome this behaviour without adding a tedious list of bindings for every possible collection (unless you convince me that it is a very bad practice to do so)
0

There are 0 best solutions below