Reputation: 9584
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)
Upvotes: 5
Views: 3459
Reputation: 17957
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)
Upvotes: 7