Skip to content

BindInterfaceToBinding

bartelink edited this page Mar 28, 2013 · 3 revisions

The Extension also provides a more direct facility to achieve the effect accomplished via ContextPreservingGet; if you have a service with multiple interfaces you can use BindInterfaceToBinding as follows:

public class Service : IServiceA, IServiceB {}
 
Bind<Service>().ToSelf().InSingletonScope();
BindInterfaceToBinding<IServiceA, Service>();
BindInterfaceToBinding<IServiceB, Service>();

Using the Version 3 Bind overloads

In Ninject Version 3 and later, one can also achieve the same effect using:

public class Service : IServiceA, IServiceB {}
 
Bind<IServiceA,IServiceB,Service>().To<Service>().InSingletonScope();

Clone this wiki locally