I have an Azure Worker Role that needs a repository. I normally use Ninject to inject these things in the constructor of objects that I create, which works fine for MVC3/4 (I’m using it with Ninject.MVC).
It doesn’t work with Azure worker roles however. I need a parameterless constructor to launch the role, so constructor injection isn’t an option. I tried using DependencyResolver.Current.GetService to get my repository (from a constructor, from the OnStart() method and from the Run() method), but it returns null every time. I think this is because the Application_Start() from MVC hasn’t been run yet? I don’t know.
Can anyone help me by explaining how I do this? Anyone?
If you use the answer provided in this question Cannot inject dependencies to Azure WorkerRole object using Spring.NET you could work something out but then use Ninject instead of Spring.NET