Ninject: allow dependency by name only

I have a WPF view \ view-model binding template where I would like to allow dependencies only on the Ninject name by name, and not by type or type + name. I want to associate my view models by name with Ninject, and then refer to the view models in views by that name to view injections (via Caliburn.Micro).

I understand that in practice, several types can be registered with the same name, but I want a convention type template and am ready to live with it. I only need to allow the "object" to bind WPF to work.

For example, is there a way:

  • Retrieve all the bindings no matter what types they are registered with.
  • A probe for binding with the corresponding name.
  • Create an instance through the binding.
+4
source share
1 answer

The only way is to link them as an object

kernel.Bind<object>().To<MyClass>().Named("A") kernel.Get<object>("A"); 
+10
source

All Articles