问题
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