Class Samurai: IWarrior {} Public Class Program {Public Stable Zero Main String [] args) {Var Colonel = New Standard Corner (); & Lt; IWarrior & gt; (). & Lt; Samurai & gt; (). When (i = & gt; {Console.WriteLine ("test"); return back;}); IWarrior warrior = kernel Go & lt; IWarrior & gt; (); }}
This is a very simple scenario, I am building a dummy interface + implementation and the NInject's and when
method back right
, and this console is also called "test" message, I thought that when ()
would receive only once per Is; & Lt; & Gt; ()
it only hopes to produce "trial" once, but magical (or not? ^ _ ^) it tests 3 times "test" ,
test test test which means when
get 3 times
Request (Another implementation of IWarrior has been added and it has been compelled, then the output number 6 (3 per binding) was done.
Why does it happen? We have some non-trivial Anyone who is investigating is bound to be bound, but calling it three times instead will be an issue.
For a single activation, the nigrate will evaluate whether it can resolve your request using the representative provided in when
. And for internal implementation of Ninject, it This can be called several times. For this, source is the source code available on Gethubub.
Conditional type could not find any means or if the argument is the time-consumer.
And as a note: these are one of the reasons because the ninin container is too slow compared to the activation request than others. In short, because it is supported for advanced relevant / conditional binding, where each activation request should be evaluated according to its context (and not cached).