[英]SignalR Ninject in Console Application (Self Hosted)
I am trying to set up Ninject with SignalR in a console application but am getting a: 我试图在控制台应用程序中使用SignalR设置Ninject,但我得到了:
System.MissingMethodException: No parameterless constructor defined for this object.
System.MissingMethodException:没有为此对象定义的无参数构造函数。
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();
You need to do it before creating the Server instance: 您需要在创建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 要么
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. 在后一种情况下,您将无法使用GlobalHost进行广播,但您可以直接使用服务器执行相同的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.