Injecting MVC and HTTP attributes and filters using Ninject

The problem: null dependencies Ninject has some fun quirks. For instance, one “bug” I came across was that if you hit an ASP.NET controller with a custom attribute, the attribute’s constructor-injected dependencies would be null on startup. For example, take the following ActionFilterAttribute: public class ForceHttpAttribute : ActionFilterAttribute { private readonly IControllerContextHelper _controllerContextHelper; public ForceHttpAttribute(IControllerContextHelper controllerContextHelper)…

Ninject InSingletonScope still creates new objects

Me: Kernel.Bind<IDataCache>().To<InMemoryDataCache>().InSingletonScope(); Ninject: Haha, nah. Here’s a new object bro. I don’t know why exactly this happens, but for some reason I’ve seen it happen in more than one project. Binding an implementation to an interface in singleton scope just DOESN’T do that. Instead, with every injection, the constructor is called and we get a…