Generics overload
- Changed IHubConnectionContext and friends to be generic. - Hub by default is Hub<IClientProxy>. We'll enable dynamic and arbitrary TClients in another commit.
This commit is contained in:
parent
9c10b89fa8
commit
217223e636
|
|
@ -3,14 +3,19 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
public class Hub : IDisposable
|
||||
public class Hub : Hub<IClientProxy>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class Hub<TClient> : IDisposable
|
||||
{
|
||||
private bool _disposed;
|
||||
private IHubConnectionContext _clients;
|
||||
private IHubConnectionContext<TClient> _clients;
|
||||
private HubCallerContext _context;
|
||||
private IGroupManager _groups;
|
||||
|
||||
public IHubConnectionContext Clients
|
||||
public IHubConnectionContext<TClient> Clients
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,15 +7,13 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
{
|
||||
public HubCallerContext(Connection connection)
|
||||
{
|
||||
ConnectionId = connection.ConnectionId;
|
||||
User = connection.User;
|
||||
Connection = connection;
|
||||
}
|
||||
|
||||
public Connection Connection { get; }
|
||||
|
||||
public ClaimsPrincipal User { get; }
|
||||
public ClaimsPrincipal User => Connection.User;
|
||||
|
||||
public string ConnectionId { get; }
|
||||
public string ConnectionId => Connection.ConnectionId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
public class HubContext<THub> : IHubContext<THub>, IHubConnectionContext
|
||||
public class HubContext<THub> : IHubContext<THub>, IHubConnectionContext<IClientProxy>
|
||||
{
|
||||
private readonly HubLifetimeManager<THub> _lifetimeManager;
|
||||
private readonly AllClientProxy<THub> _all;
|
||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
_all = new AllClientProxy<THub>(_lifetimeManager);
|
||||
}
|
||||
|
||||
public IHubConnectionContext Clients => this;
|
||||
public IHubConnectionContext<IClientProxy> Clients => this;
|
||||
|
||||
public virtual IClientProxy All => _all;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,22 +10,34 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
public class HubEndPoint<THub> : EndPoint where THub : Hub
|
||||
public class HubEndPoint<THub> : HubEndPoint<THub, IClientProxy> where THub : Hub<IClientProxy>
|
||||
{
|
||||
public HubEndPoint(HubLifetimeManager<THub> lifetimeManager,
|
||||
IHubContext<THub> hubContext,
|
||||
InvocationAdapterRegistry registry,
|
||||
ILogger<HubEndPoint<THub>> logger,
|
||||
IServiceScopeFactory serviceScopeFactory) : base(lifetimeManager, hubContext, registry, logger, serviceScopeFactory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class HubEndPoint<THub, TClient> : EndPoint where THub : Hub<TClient>
|
||||
{
|
||||
private readonly Dictionary<string, Func<Connection, InvocationDescriptor, Task<InvocationResultDescriptor>>> _callbacks
|
||||
= new Dictionary<string, Func<Connection, InvocationDescriptor, Task<InvocationResultDescriptor>>>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, Type[]> _paramTypes = new Dictionary<string, Type[]>();
|
||||
|
||||
private readonly HubLifetimeManager<THub> _lifetimeManager;
|
||||
private readonly IHubContext<THub> _hubContext;
|
||||
private readonly ILogger<HubEndPoint<THub>> _logger;
|
||||
private readonly IHubContext<THub, TClient> _hubContext;
|
||||
private readonly ILogger<HubEndPoint<THub, TClient>> _logger;
|
||||
private readonly InvocationAdapterRegistry _registry;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
|
||||
public HubEndPoint(HubLifetimeManager<THub> lifetimeManager,
|
||||
IHubContext<THub> hubContext,
|
||||
IHubContext<THub, TClient> hubContext,
|
||||
InvocationAdapterRegistry registry,
|
||||
ILogger<HubEndPoint<THub>> logger,
|
||||
ILogger<HubEndPoint<THub, TClient>> logger,
|
||||
IServiceScopeFactory serviceScopeFactory)
|
||||
{
|
||||
_lifetimeManager = lifetimeManager;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
public interface IHubConnectionContext
|
||||
public interface IHubConnectionContext<TClient>
|
||||
{
|
||||
IClientProxy All { get; }
|
||||
TClient All { get; }
|
||||
|
||||
IClientProxy Client(string connectionId);
|
||||
TClient Client(string connectionId);
|
||||
|
||||
IClientProxy Group(string groupName);
|
||||
TClient Group(string groupName);
|
||||
|
||||
IClientProxy User(string userId);
|
||||
TClient User(string userId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
public interface IHubContext<THub>
|
||||
public interface IHubContext<THub, TClient>
|
||||
{
|
||||
IHubConnectionContext<TClient> Clients { get; }
|
||||
}
|
||||
|
||||
public interface IHubContext<THub> : IHubContext<THub, IClientProxy>
|
||||
{
|
||||
IHubConnectionContext Clients { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue