I have an interface IAdapdor
, and several concrete implementations. Using Ninject 3.0, I bind them all by name:
IKernel kernel = new StandardKernel();
kernel.Bind<IAdapdor>().To<Adaptor1>().Named("Adaptor1");
kernel.Bind<IAdapdor>().To<Adaptor2>().Named("Adaptor2");
...
How can I achieve this using Ninject conventions extension?
To be more specific, I'm looking for something in the line:
kernel.Bind(x => x.FromThisAssembly()
.SelectAllClasses()
.InheritedFrom<IAdapdor>()
.BindByClassName()); // <-- BindByClassName() does not really exist
You can customize the convention created bindings using the Configure
method. So you can use that to register your bindings with Named
:
kernel.Bind(x => x
.FromThisAssembly()
.SelectAllClasses().InheritedFrom<IAdapdor>()
.BindAllInterfaces()
.Configure((b, c) => b.Named(c.Name)));