From de21ce16377975c4287a75a3ddab4bd8a1307b94 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 5 Jul 2017 23:50:54 -0700 Subject: [PATCH] Expose IGroupManager on IHubContext (#638) - Adding groups is no longer coupled to the incoming connection so we should expose it outside of the hub itself. --- samples/ChatSample/PresenceHubLifetimeManager.cs | 3 +-- src/Microsoft.AspNetCore.SignalR/HubContext.cs | 8 +++++--- src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs | 2 +- src/Microsoft.AspNetCore.SignalR/IHubContext.cs | 4 +++- src/Microsoft.AspNetCore.SignalR/Proxies.cs | 1 - 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/samples/ChatSample/PresenceHubLifetimeManager.cs b/samples/ChatSample/PresenceHubLifetimeManager.cs index 991f46a168..841eeaa907 100644 --- a/samples/ChatSample/PresenceHubLifetimeManager.cs +++ b/samples/ChatSample/PresenceHubLifetimeManager.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; -using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.SignalR.Redis; @@ -113,7 +112,7 @@ namespace ChatSample hub.Clients = _hubContext.Clients; hub.Context = new HubCallerContext(connection); - hub.Groups = new GroupManager(this); + hub.Groups = _hubContext.Groups; try { diff --git a/src/Microsoft.AspNetCore.SignalR/HubContext.cs b/src/Microsoft.AspNetCore.SignalR/HubContext.cs index 3464e78417..c527174b6d 100644 --- a/src/Microsoft.AspNetCore.SignalR/HubContext.cs +++ b/src/Microsoft.AspNetCore.SignalR/HubContext.cs @@ -6,17 +6,19 @@ namespace Microsoft.AspNetCore.SignalR public class HubContext : IHubContext, IHubClients where THub : Hub { private readonly HubLifetimeManager _lifetimeManager; - private readonly AllClientProxy _all; public HubContext(HubLifetimeManager lifetimeManager) { _lifetimeManager = lifetimeManager; - _all = new AllClientProxy(_lifetimeManager); + All = new AllClientProxy(_lifetimeManager); + Groups = new GroupManager(lifetimeManager); } public IHubClients Clients => this; - public virtual IClientProxy All => _all; + public virtual IClientProxy All { get; } + + public virtual IGroupManager Groups { get; } public virtual IClientProxy Client(string connectionId) { diff --git a/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs b/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs index 0560101270..4ade79b872 100644 --- a/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs +++ b/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs @@ -363,7 +363,7 @@ namespace Microsoft.AspNetCore.SignalR { hub.Clients = _hubContext.Clients; hub.Context = new HubCallerContext(connection); - hub.Groups = new GroupManager(_lifetimeManager); + hub.Groups = _hubContext.Groups; } private bool IsChannel(Type type, out Type payloadType) diff --git a/src/Microsoft.AspNetCore.SignalR/IHubContext.cs b/src/Microsoft.AspNetCore.SignalR/IHubContext.cs index 77b1ba181a..88c004aec2 100644 --- a/src/Microsoft.AspNetCore.SignalR/IHubContext.cs +++ b/src/Microsoft.AspNetCore.SignalR/IHubContext.cs @@ -8,8 +8,10 @@ using System.Threading.Tasks; namespace Microsoft.AspNetCore.SignalR { - public interface IHubContext where THub: Hub + public interface IHubContext where THub : Hub { IHubClients Clients { get; } + + IGroupManager Groups { get; } } } diff --git a/src/Microsoft.AspNetCore.SignalR/Proxies.cs b/src/Microsoft.AspNetCore.SignalR/Proxies.cs index bf4359cdbd..048ee43ba9 100644 --- a/src/Microsoft.AspNetCore.SignalR/Proxies.cs +++ b/src/Microsoft.AspNetCore.SignalR/Proxies.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Sockets; namespace Microsoft.AspNetCore.SignalR {