Reputation: 24325
I have three projects that will use DI. My project is an ASP.NET MVC 3 site. I installed the ninject MVC package from nuget which added my bootstrapper. I registered my binding.
NinjectMVC3.cs
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IUserService>().To<UserService>();
}
I have a separate project that contains the UserService and IUserService. In that project I also have a singleton factory class to create my services.
public class ServiceFactory : BaseFactory<ServiceFactory>
{
[Inject]
public IUserService UserService { get; set; }
}
Is there a reason why the above is always null when I call ServiceFactory.Instance.UserService?
Upvotes: 0
Views: 600
Reputation: 32725
Guessing: Most likely the factory isn't created by Ninject.
But as you shouldn't use the Singleton pattern anyway when doing Dependency Injection this should be easy to solve.
IUserService
to the constructor of any object that needs to know it.kernel.Bind<IUserService>().To<UserService>().InSingletonScope();
Upvotes: 2