Ninject: how to bind an interface depending on the target assembly

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

+4
source share
1 answer

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"); 
+5
source

Source: https://habr.com/ru/post/1392054/


All Articles