Permalink
Browse files

Changed the way hubs are mapped in routing host.

  • Loading branch information...
1 parent 149caf4 commit b438d4cb40847bb1938478470f831a80aceb5005 @davidfowl davidfowl committed Mar 22, 2012
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
-using SignalR.Infrastructure;
+using SignalR.Hubs;
namespace SignalR.Hosting.Common.Routing
{
public class RouteManager
{
private readonly IDependencyResolver _resolver;
private readonly Dictionary<string, Type> _connectionMapping = new Dictionary<string, Type>();
+ private string _hubPath;
public RouteManager(IDependencyResolver resolver)
{
@@ -22,6 +23,11 @@ public RouteManager(IDependencyResolver resolver)
}
}
+ public void MapHubs(string path)
+ {
+ _hubPath = path;
+ }
+
public bool TryGetConnection(Uri uri, out PersistentConnection connection)
{
return TryGetConnection(uri.LocalPath, out connection);
@@ -31,6 +37,13 @@ public bool TryGetConnection(string path, out PersistentConnection connection)
{
connection = null;
+ if (!String.IsNullOrEmpty(_hubPath) &&
+ path.StartsWith(_hubPath, StringComparison.OrdinalIgnoreCase))
+ {
+ connection = new HubDispatcher(_hubPath);
+ return true;
+ }
+
foreach (var pair in _connectionMapping)
{
// If the url matches then create the connection type
@@ -1,7 +1,4 @@
-using System;
-using SignalR.Hosting.Common.Routing;
-using SignalR.Hubs;
-using SignalR.Infrastructure;
+using SignalR.Hosting.Common.Routing;
namespace SignalR.Hosting.Common
{
@@ -20,19 +17,26 @@ public RoutingHost(IDependencyResolver resolver)
_routeManager = new RouteManager(resolver);
}
- public void MapConnection<TConnection>(string path) where TConnection : PersistentConnection
+ public RoutingHost MapHubs()
{
- _routeManager.MapConnection<TConnection>(path);
+ return MapHubs("/signalr");
+ }
+
+ public RoutingHost MapHubs(string path)
+ {
+ _routeManager.MapHubs(path);
+
+ return this;
}
- public virtual bool TryGetConnection(string path, out PersistentConnection connection)
+ public RoutingHost MapConnection<TConnection>(string path) where TConnection : PersistentConnection
{
- if (path.StartsWith("/signalr", StringComparison.OrdinalIgnoreCase))
- {
- connection = new HubDispatcher("/signalr");
- return true;
- }
+ _routeManager.MapConnection<TConnection>(path);
+ return this;
+ }
+ public bool TryGetConnection(string path, out PersistentConnection connection)
+ {
return _routeManager.TryGetConnection(path, out connection);
}
}
@@ -39,6 +39,7 @@ public void DisconnectFiresForPersistentConnectionWhenClientGoesAway()
public void DisconnectFiresForHubsWhenConnectionGoesAway()
{
var host = new MemoryHost();
+ host.MapHubs();
var configurationManager = host.DependencyResolver.Resolve<IConfigurationManager>();
configurationManager.DisconnectTimeout = TimeSpan.Zero;
configurationManager.HeartBeatInterval = TimeSpan.FromSeconds(5);

0 comments on commit b438d4c

Please sign in to comment.