SignalR change DisconnectTimeout when using custom resolver

我只是一个虾纸丫 提交于 2019-12-08 04:13:31

问题


I'm using a custom resolver when running SignalR to make use of dependency injection. But it seems like my DisconnectTimeout & KeepAlive values aren't used after this. I've read some comments that the Configuration is ignored then using a custom resolver. But settings the GlobalHost.DependencyResolver should do the trick. But after changing it, the disconnect timeout still seems to be 30 seconds..

Code:

var resolver = new NinjectSignalRDependencyResolver(Program.kernel);
GlobalHost.DependencyResolver = resolver;
GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(9);
GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(3);

app.Map("/signalr", map =>
{
    map.UseCors(CorsOptions.AllowAll);
    var hubConfiguration = new HubConfiguration
    {
        Resolver = resolver,
        EnableJSONP = true,
        EnableDetailedErrors = true
    };
    map.RunSignalR(hubConfiguration);
});

Is there anything I'm doing wrong or not thinking about?


回答1:


The following code is working for me

  var wDependenctResolver = new SignalRUnityResolver(wUnityContainer);
  GlobalHost.DependencyResolver = wDependenctResolver;
  GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(30);
  GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(6);
  GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(2);
  try
  {
    var hubConfiguration = new HubConfiguration
    {

      EnableDetailedErrors = true,
      EnableJavaScriptProxies = true
    };
    appBuilder.MapSignalR("/signalr", hubConfiguration);

  }
  catch (Exception ex)
  {
    Console.WriteLine("Failed to initialize or map SignalR", ex);
  }


来源:https://stackoverflow.com/questions/25724067/signalr-change-disconnecttimeout-when-using-custom-resolver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!