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.
This commit is contained in:
parent
2597e52e53
commit
de21ce1637
|
|
@ -4,7 +4,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.AspNetCore.Sockets;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.AspNetCore.SignalR.Redis;
|
using Microsoft.AspNetCore.SignalR.Redis;
|
||||||
|
|
@ -113,7 +112,7 @@ namespace ChatSample
|
||||||
|
|
||||||
hub.Clients = _hubContext.Clients;
|
hub.Clients = _hubContext.Clients;
|
||||||
hub.Context = new HubCallerContext(connection);
|
hub.Context = new HubCallerContext(connection);
|
||||||
hub.Groups = new GroupManager<THub>(this);
|
hub.Groups = _hubContext.Groups;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,19 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
public class HubContext<THub> : IHubContext<THub>, IHubClients where THub : Hub
|
public class HubContext<THub> : IHubContext<THub>, IHubClients where THub : Hub
|
||||||
{
|
{
|
||||||
private readonly HubLifetimeManager<THub> _lifetimeManager;
|
private readonly HubLifetimeManager<THub> _lifetimeManager;
|
||||||
private readonly AllClientProxy<THub> _all;
|
|
||||||
|
|
||||||
public HubContext(HubLifetimeManager<THub> lifetimeManager)
|
public HubContext(HubLifetimeManager<THub> lifetimeManager)
|
||||||
{
|
{
|
||||||
_lifetimeManager = lifetimeManager;
|
_lifetimeManager = lifetimeManager;
|
||||||
_all = new AllClientProxy<THub>(_lifetimeManager);
|
All = new AllClientProxy<THub>(_lifetimeManager);
|
||||||
|
Groups = new GroupManager<THub>(lifetimeManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IHubClients Clients => this;
|
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)
|
public virtual IClientProxy Client(string connectionId)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -363,7 +363,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
{
|
{
|
||||||
hub.Clients = _hubContext.Clients;
|
hub.Clients = _hubContext.Clients;
|
||||||
hub.Context = new HubCallerContext(connection);
|
hub.Context = new HubCallerContext(connection);
|
||||||
hub.Groups = new GroupManager<THub>(_lifetimeManager);
|
hub.Groups = _hubContext.Groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsChannel(Type type, out Type payloadType)
|
private bool IsChannel(Type type, out Type payloadType)
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,10 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.SignalR
|
namespace Microsoft.AspNetCore.SignalR
|
||||||
{
|
{
|
||||||
public interface IHubContext<THub> where THub: Hub
|
public interface IHubContext<THub> where THub : Hub
|
||||||
{
|
{
|
||||||
IHubClients Clients { get; }
|
IHubClients Clients { get; }
|
||||||
|
|
||||||
|
IGroupManager Groups { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Sockets;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.SignalR
|
namespace Microsoft.AspNetCore.SignalR
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue