控制台应用程序中的SignalR Ninject(自托管)

时间:2012-07-22 19:04:02

标签: c# signalr

我正在尝试在控制台应用程序中使用SignalR设置Ninject,但我得到了:

  

System.MissingMethodException:没有为此对象定义无参数构造函数。

我的代码如下所示:

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();

1 个答案:

答案 0 :(得分:2)

您需要在创建Server实例之前执行此操作:

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

在服务器上设置依赖项解析器:

static void Main(string[] args)
{
    string url = "http://localhost:8081/";
    var server = new Server(url, NinjectDependencyResolver(Kernel));

    server.MapHubs();

    // Start the server
    server.Start();

在后一种情况下,您将无法使用GlobalHost进行广播,但您可以直接使用服务器执行相同的操作。

相关问题