Trying to get ninject and signalR to work properly

asp.net, c#, ninject, signalr

Solution

Your problem is that you have a `private` property, and Ninject by default doesn't inject private properties.

So either you make your property `public` or you can enable non public property injection with:

kernel.Settings.InjectNonPublic = true;

I'm not familiar with the dependency injection in SignalR (so maybe it's not supported) but you should always prefer constructor injection so your `Hub` should be like:

public class MatchMaker : Hub
{    
    private readonly ISoloUserRepository soloUsers;

    public MatchMaker(ISoloUserRepository soloUsers) 
    {
        this.soloUsers = soloUsers;
    }
}

Problem

In my NinjectWebCommon.cs file, under the `RegisterServices` method I have the following: ``` private static void RegisterServices(IKernel kernel) { kernel.Bind<IProfileRepository>().To<ProfileRepository>(); kernel.Bind<IMatchUpService>().To<MatchUpService>(); kernel.Bind<ISoloUserRepository>().To<SoloUserRepository>(); SignalR.GlobalHost.DependencyResolver = new SignalR.Ninject.NinjectDependencyResolver(kernel); } ``` I am trying to inject SoloUserRepository into my hub class, here is my hub class: ``` public class MatchMaker : Hub { [Inject] private ISoloUserRepository soloUsers { get; set; } } ``` For some reason when I try to use the `soloUsers` object in my Hub class, i get `object reference not set to instance of an object` because the `soloUsers` object is never being instantiated or, in other words, not injected. Am I doing something wrong?

Original source