How do I get a list of bindings which are bound to a particular implementation type?
IKernel.Bind<IService>().To(implementationType);
something like this ?
var bindings = IKernel.GetBindings(typeof(IService))
.Where(b=>b.ImplementationType==implementationType)
Not easily. If you can somehow construct a Ninject Context, you can do
Kernel.GetBindings(typeof(IService))
.Where(b => b.GetProvider(context).Type == implementationType)
UPDATE
Actually there is an alternate way to do it. When declaring your bindings you can supply metadata
Kernel.Bind<IService>().To(implementationType)
.WithMetadata("type", implementationType);
Then you can get all bindings by doing this
Kernel.GetBindings(typeof(IService))
.Where(b => b.Metadata.Get<Type>("type") == implementationType)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With