문제

I have a scenario where I have a bunch of features in an application which are being enabled and disabled on the basis of network devices being present on the network. I'm using Ninject to manage my current feature tree within the application.

What I want to do is to be able to add and remove a set of bindings to my kernel while the application is running. I would like to use something like a Ninject module to be able to bundle these together, however I can't figure out how to add/remove a Module from an existing Kernel.

Anyone know how to do this or have a better option?

도움이 되었습니까?

해결책

Don't try to add/remove after the first resolve! The kernel should be configured completely before resolving objects and the configuration should not change anymore after the first resolve.

Use conditional bindings instead:

Bind<INetworkDevice>().To<NetworkPrinter>().When(ctx => PrinterIsEnabled());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top