From the hints in the answer by Remo and comment by Filip along with a significant amount of debugging time, I found out the use of this.resolver.Get(serviceType)
instead of this.resolver.TryGet(serviceType)
in GetService() implementation was the culprit in my situation.
I plan a detailed blog post about this but the short of it is that once we have the NinjectDependencyResolver plugged into MVC using the line:
GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
and we don't define Framework level dependency bindings (e.g. IHostBufferPolicySelector etc.), an exception is raised by the Get()
method for some framework level dependencies when they are not resolved through Ninject. Using TryGet()
does not raise an exception and the framework falls back to default dependencies for unresolved (a.ka. null) dependencies like IHostBufferPolicySelector. So, the options are
- Use the TryGet() method to resolve dependencies.
- Wrap Get in Try/Catch and discard the exception.