Probably a simple question, but I did not find anything in the documentation or on SO that directly answers it.
I had to work with the Ninject When(Func<IRequest, bool> condition)
extension method for the first time, and got hung up for a bit with null object exceptions. I figured out that the IRequest.Target
property is sometimes null and I've seen some other examples using When
that check for a null Target
as well.
I'm curious about the conditions under which Ninject executes the callback without having a value for Target
. When creating a binding of the form
Bind<T1>()
.To<T2>
.When(r => SomeTest(r.Target));
I initially and erroneously assumed that there would always be a valid Target
of type T1
when the binding was being executed.
It is null for the root object because there is no target in this case. (kernel.Get<MyCompositionRoot>()
)