Skip to content

Commit f3a1b31

Browse files
Revert part of "Add base interface for IHubContext (#33443)" (#34174)
1 parent 0ad1efc commit f3a1b31

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

src/SignalR/server/Core/src/IHubContext.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ public interface IHubContext
2222
/// <summary>
2323
/// A context abstraction for a hub.
2424
/// </summary>
25-
public interface IHubContext<out THub> : IHubContext where THub : Hub
25+
public interface IHubContext<out THub> where THub : Hub
2626
{
27+
/// <summary>
28+
/// Gets a <see cref="IHubClients"/> that can be used to invoke methods on clients connected to the hub.
29+
/// </summary>
30+
IHubClients Clients { get; }
31+
32+
/// <summary>
33+
/// Gets a <see cref="IGroupManager"/> that can be used to add and remove connections to named groups.
34+
/// </summary>
35+
IGroupManager Groups { get; }
2736
}
2837
}

src/SignalR/server/Core/src/Internal/HubContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Microsoft.AspNetCore.SignalR.Internal
55
{
6-
internal class HubContext<THub> : IHubContext<THub> where THub : Hub
6+
internal class HubContext<THub> : IHubContext, IHubContext<THub> where THub : Hub
77
{
88
private readonly HubLifetimeManager<THub> _lifetimeManager;
99
private readonly IHubClients _clients;

src/SignalR/server/Core/src/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
*REMOVED*abstract Microsoft.AspNetCore.SignalR.HubLifetimeManager<THub>.SendUsersAsync(System.Collections.Generic.IReadOnlyList<string!>! userIds, string! methodName, object?[]? args, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
2222
*REMOVED*Microsoft.AspNetCore.SignalR.IClientProxy.SendCoreAsync(string! method, object?[]? args, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
2323
*REMOVED*virtual Microsoft.AspNetCore.SignalR.HubConnectionContext.User.get -> System.Security.Claims.ClaimsPrincipal?
24-
*REMOVED*Microsoft.AspNetCore.SignalR.IHubContext<THub>.Clients.get -> Microsoft.AspNetCore.SignalR.IHubClients!
25-
*REMOVED*Microsoft.AspNetCore.SignalR.IHubContext<THub>.Groups.get -> Microsoft.AspNetCore.SignalR.IGroupManager!
2624
Microsoft.AspNetCore.SignalR.IHubContext
2725
Microsoft.AspNetCore.SignalR.IHubContext.Clients.get -> Microsoft.AspNetCore.SignalR.IHubClients!
2826
Microsoft.AspNetCore.SignalR.IHubContext.Groups.get -> Microsoft.AspNetCore.SignalR.IGroupManager!

src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4437,6 +4437,33 @@ public async Task ClientsCallerPropertyCanBeUsedOutsideOfHub()
44374437
}
44384438
}
44394439

4440+
[Fact]
4441+
public async Task CanSendThroughIHubContext()
4442+
{
4443+
using (StartVerifiableLog())
4444+
{
4445+
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
4446+
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
4447+
4448+
using var client = new TestClient();
4449+
4450+
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
4451+
4452+
// Wait for a connection, or for the endpoint to fail.
4453+
await client.Connected.OrThrowIfOtherFails(connectionHandlerTask).DefaultTimeout();
4454+
4455+
IHubContext context = (IHubContext)serviceProvider.GetRequiredService<IHubContext<MethodHub>>();
4456+
await context.Clients.All.SendAsync("Send", "test");
4457+
4458+
var message = await client.ReadAsync().DefaultTimeout();
4459+
var invocation = Assert.IsType<InvocationMessage>(message);
4460+
4461+
Assert.Single(invocation.Arguments);
4462+
Assert.Equal("test", invocation.Arguments[0]);
4463+
Assert.Equal("Send", invocation.Target);
4464+
}
4465+
}
4466+
44404467
[Fact]
44414468
public async Task ConnectionCloseCleansUploadStreams()
44424469
{
@@ -4500,33 +4527,6 @@ public async Task SpecificHubOptionForMaximumReceiveMessageSizeIsUsedOverGlobalH
45004527
}
45014528
}
45024529

4503-
[Fact]
4504-
public async Task CanSendThroughIHubContext()
4505-
{
4506-
using (StartVerifiableLog())
4507-
{
4508-
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
4509-
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
4510-
4511-
using var client = new TestClient();
4512-
4513-
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
4514-
4515-
// Wait for a connection, or for the endpoint to fail.
4516-
await client.Connected.OrThrowIfOtherFails(connectionHandlerTask).DefaultTimeout();
4517-
4518-
IHubContext context = serviceProvider.GetRequiredService<IHubContext<MethodHub>>();
4519-
await context.Clients.All.SendAsync("Send", "test");
4520-
4521-
var message = await client.ReadAsync().DefaultTimeout();
4522-
var invocation = Assert.IsType<InvocationMessage>(message);
4523-
4524-
Assert.Single(invocation.Arguments);
4525-
Assert.Equal("test", invocation.Arguments[0]);
4526-
Assert.Equal("Send", invocation.Target);
4527-
}
4528-
}
4529-
45304530
[Fact]
45314531
public async Task CanSendThroughIHubContextBaseHub()
45324532
{

0 commit comments

Comments
 (0)