Ninject Rebind at runtime, can it be used as a switching function?

Firstly, my question only applies to web applications, and I try to configure most of my Ninject bindings using InRequestScope permission.

I think about ways to switch functions, and I thought I should call:

kernel.Rebind<IInterface>().To<RealImplementation>().InRequestScope();

while the website is still up and running and the switch has been clicked. If I then decide to disable this feature, I could call

kernel.Rebind<IInterface>().To<EmptyImplementation>().InRequestScope();

My thinking is that InRequestScope will protect any requested code requests, but allow new requests to get a new function.

Does anyone know from experience (or a deeper understanding of Ninject) if this can work, or if it causes more problems for me. I looked at MEF superficially, so this will be my next port of call if Ninject is not the best tool to work in this case.

+5
source share
1 answer

One of the potential sources of the problem is that while the kernel is thread safe, you will need to click one switch, otherwise you are in a race so that everything switches as an atomic action to in-flight requests. (This is, in principle, I did not consider the code given this question).

Having said that, nothing comes to mind, which can lead to a problem.

, / , , , , , , . , AutoFac , Factory , , . .

.ToMethod(ctx=> return /* Toggle-based creation*/)? (, , Rebind). ( ) .

0

All Articles