Reputation: 5869
I am trying to set up Ninject with SignalR in a console application but am getting a:
System.MissingMethodException: No parameterless constructor defined for this object.
My code looks like this:
static void Main(string[] args)
{
string url = "http://localhost:8081/";
var server = new Server(url);
// Map the default hub url (/signalr)
GlobalHost.DependencyResolver = new NinjectDependencyResolver(Kernel);
server.MapHubs();
// Start the server
server.Start();
Upvotes: 0
Views: 633
Reputation: 38885
You need to do it before creating the Server instance:
static void Main(string[] args)
{
GlobalHost.DependencyResolver = new NinjectDependencyResolver(Kernel);
string url = "http://localhost:8081/";
var server = new Server(url);
// Map the default hub url (/signalr)
server.MapHubs();
// Start the server
server.Start();
OR
Setup the dependency resolver on the server itself:
static void Main(string[] args)
{
string url = "http://localhost:8081/";
var server = new Server(url, NinjectDependencyResolver(Kernel));
server.MapHubs();
// Start the server
server.Start();
In the latter case, you won't be able to use GlobalHost for broadcasting but you can use the server directly to do the same thing.
Upvotes: 2