In my MVC3 project I\'ve setup my kernel to Ninject the Entityframework context on a InRequestScope basis, this works perfect. But I have a ba
Thanks to Ruben I found a solution, however there sneaked in a little bug there in his pseudo code and since its a monday and Im tired I didnt see it right away :D
StandardScopeCallbacks.Request
Is a delegate and
StandardScopeCallbacks.Request ?? StandardScopeCallbacks.Thread
will always return the left side since the delegate will never be null.
There are two ways of doing this correctly,
public static IBindingWhenInNamedWithOrOnSyntax InRequestFallbackScope(this IBindingWhenInNamedWithOrOnSyntax binding)
{
Func fallbackCallback = ctx => StandardScopeCallbacks.Request(ctx) ?? StandardScopeCallbacks.Thread(ctx);
binding.Binding.ScopeCallback = fallbackCallback;
return binding;
}
.InScope(ctx => StandardScopeCallbacks.Request(ctx) ?? StandardScopeCallbacks.Thread(ctx))