Pato
Pato

Reputation: 679

Ninject: How to bind interface depending on target assembly

I have an interface implemented by two different classes. Then, how can I say to Ninject that I want to bind it to implementation A in some assembly and to implementation B in some other assembly ?

Upvotes: 4

Views: 1014

Answers (1)

Wim Coenen
Wim Coenen

Reputation: 66783

You can use contextual binding:

Bind<IFoo>.To<Foo>.When(request =>
    request.Target.Type.Assembly.FullName == "someAssembly");
Bind<IFoo>.To<Bar>.When(request =>
    request.Target.Type.Assembly.FullName == "someOtherAssembly");

Upvotes: 5

Related Questions