diff --git a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/BroadcastBenchmark.cs b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/BroadcastBenchmark.cs index db34fb3954..e9e6734987 100644 --- a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/BroadcastBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/BroadcastBenchmark.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks [Benchmark] public Task InvokeAsyncAll() { - return _hubContext.All.InvokeAsync("Method"); + return _hubContext.Clients.All.InvokeAsync("Method"); } } } diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubClients.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubClients.cs new file mode 100644 index 0000000000..2a16528ec3 --- /dev/null +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubClients.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.SignalR +{ + public class HubClients : IHubClients + { + private readonly HubLifetimeManager _lifetimeManager; + + public HubClients(HubLifetimeManager lifetimeManager) + { + _lifetimeManager = lifetimeManager; + All = new AllClientProxy(_lifetimeManager); + } + + public IClientProxy All { get; } + + public IClientProxy AllExcept(IReadOnlyList excludedIds) + { + return new AllClientsExceptProxy(_lifetimeManager, excludedIds); + } + + public IClientProxy Client(string connectionId) + { + return new SingleClientProxy(_lifetimeManager, connectionId); + } + + public IClientProxy Group(string groupName) + { + return new GroupProxy(_lifetimeManager, groupName); + } + + public IClientProxy GroupExcept(string groupName, IReadOnlyList excludeIds) + { + return new GroupExceptProxy(_lifetimeManager, groupName, excludeIds); + } + + public IClientProxy MultipleClients(IReadOnlyList connectionIds) + { + return new MultipleClientProxy(_lifetimeManager, connectionIds); + } + + public IClientProxy User(string userId) + { + return new UserProxy(_lifetimeManager, userId); + } + } +} diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubClients`T.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubClients`T.cs new file mode 100644 index 0000000000..4af7211a8d --- /dev/null +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubClients`T.cs @@ -0,0 +1,52 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.AspNetCore.SignalR +{ + public class HubClients : IHubClients + { + private readonly HubLifetimeManager _lifetimeManager; + + public HubClients(HubLifetimeManager lifetimeManager) + { + _lifetimeManager = lifetimeManager; + All = TypedClientBuilder.Build(new AllClientProxy(_lifetimeManager)); + } + + public T All { get; } + + public T AllExcept(IReadOnlyList excludedIds) + { + return TypedClientBuilder.Build(new AllClientsExceptProxy(_lifetimeManager, excludedIds)); + } + + public virtual T Client(string connectionId) + { + return TypedClientBuilder.Build(new SingleClientProxy(_lifetimeManager, connectionId)); + } + + public T MultipleClients(IReadOnlyList connectionIds) + { + return TypedClientBuilder.Build(new MultipleClientProxy(_lifetimeManager, connectionIds)); + } + + public virtual T Group(string groupName) + { + return TypedClientBuilder.Build(new GroupProxy(_lifetimeManager, groupName)); + } + + public T GroupExcept(string groupName, IReadOnlyList excludeIds) + { + return TypedClientBuilder.Build(new GroupExceptProxy(_lifetimeManager, groupName, excludeIds)); + } + + public virtual T User(string userId) + { + return TypedClientBuilder.Build(new UserProxy(_lifetimeManager, userId)); + } + } +} diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubContext.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubContext.cs index 56ebe6f254..cf2cfdf961 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubContext.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubContext.cs @@ -1,55 +1,22 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; - namespace Microsoft.AspNetCore.SignalR { - public class HubContext : IHubContext, IHubClients where THub : Hub + public class HubContext : IHubContext where THub : Hub { private readonly HubLifetimeManager _lifetimeManager; + private readonly IHubClients _clients; public HubContext(HubLifetimeManager lifetimeManager) { _lifetimeManager = lifetimeManager; - All = new AllClientProxy(_lifetimeManager); + _clients = new HubClients(_lifetimeManager); Groups = new GroupManager(lifetimeManager); } - public IHubClients Clients => this; - - public virtual IClientProxy All { get; } + public IHubClients Clients => _clients; public virtual IGroupManager Groups { get; } - - public IClientProxy AllExcept(IReadOnlyList excludedIds) - { - return new AllClientsExceptProxy(_lifetimeManager, excludedIds); - } - - public virtual IClientProxy Client(string connectionId) - { - return new SingleClientProxy(_lifetimeManager, connectionId); - } - - public virtual IClientProxy Group(string groupName) - { - return new GroupProxy(_lifetimeManager, groupName); - } - - public IClientProxy GroupExcept(string groupName, IReadOnlyList excludeIds) - { - return new GroupExceptProxy(_lifetimeManager, groupName, excludeIds); - } - - public virtual IClientProxy User(string userId) - { - return new UserProxy(_lifetimeManager, userId); - } - - public virtual IClientProxy MultipleClients(IReadOnlyList connectionIds) - { - return new MultipleClientProxy(_lifetimeManager, connectionIds); - } } } diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubContext`T.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubContext`T.cs index 9d3c2131e8..e91577204b 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubContext`T.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubContext`T.cs @@ -5,53 +5,22 @@ using System.Collections.Generic; namespace Microsoft.AspNetCore.SignalR { - public class HubContext : IHubContext, IHubClients + public class HubContext : IHubContext where THub : Hub where T : class { private readonly HubLifetimeManager _lifetimeManager; + private readonly IHubClients _clients; public HubContext(HubLifetimeManager lifetimeManager) { _lifetimeManager = lifetimeManager; - All = TypedClientBuilder.Build(new AllClientProxy(_lifetimeManager)); + _clients = new HubClients(_lifetimeManager); Groups = new GroupManager(lifetimeManager); } - public IHubClients Clients => this; - - public virtual T All { get; } + public IHubClients Clients => _clients; public virtual IGroupManager Groups { get; } - - public T AllExcept(IReadOnlyList excludedIds) - { - return TypedClientBuilder.Build(new AllClientsExceptProxy(_lifetimeManager, excludedIds)); - } - - public virtual T Client(string connectionId) - { - return TypedClientBuilder.Build(new SingleClientProxy(_lifetimeManager, connectionId)); - } - - public T MultipleClients(IReadOnlyList connectionIds) - { - return TypedClientBuilder.Build(new MultipleClientProxy(_lifetimeManager, connectionIds)); - } - - public virtual T Group(string groupName) - { - return TypedClientBuilder.Build(new GroupProxy(_lifetimeManager, groupName)); - } - - public T GroupExcept(string groupName, IReadOnlyList excludeIds) - { - return TypedClientBuilder.Build(new GroupExceptProxy(_lifetimeManager, groupName, excludeIds)); - } - - public virtual T User(string userId) - { - return TypedClientBuilder.Build(new UserProxy(_lifetimeManager, userId)); - } } }