Ver Fonte

Revert part of "Add base interface for IHubContext (#33443)" (#34174)

Brennan há 4 anos atrás
pai
commit
f3a1b3153b

+ 10 - 1
src/SignalR/server/Core/src/IHubContext.cs

@@ -22,7 +22,16 @@ namespace Microsoft.AspNetCore.SignalR
     /// <summary>
     /// A context abstraction for a hub.
     /// </summary>
-    public interface IHubContext<out THub> : IHubContext where THub : Hub
+    public interface IHubContext<out THub> where THub : Hub
     {
+        /// <summary>
+        /// Gets a <see cref="IHubClients"/> that can be used to invoke methods on clients connected to the hub.
+        /// </summary>
+        IHubClients Clients { get; }
+
+        /// <summary>
+        /// Gets a <see cref="IGroupManager"/> that can be used to add and remove connections to named groups.
+        /// </summary>
+        IGroupManager Groups { get; }
     }
 }

+ 1 - 1
src/SignalR/server/Core/src/Internal/HubContext.cs

@@ -3,7 +3,7 @@
 
 namespace Microsoft.AspNetCore.SignalR.Internal
 {
-    internal class HubContext<THub> : IHubContext<THub> where THub : Hub
+    internal class HubContext<THub> : IHubContext, IHubContext<THub> where THub : Hub
     {
         private readonly HubLifetimeManager<THub> _lifetimeManager;
         private readonly IHubClients _clients;

+ 0 - 2
src/SignalR/server/Core/src/PublicAPI.Unshipped.txt

@@ -21,8 +21,6 @@
 *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!
 *REMOVED*Microsoft.AspNetCore.SignalR.IClientProxy.SendCoreAsync(string! method, object?[]? args, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
 *REMOVED*virtual Microsoft.AspNetCore.SignalR.HubConnectionContext.User.get -> System.Security.Claims.ClaimsPrincipal?
-*REMOVED*Microsoft.AspNetCore.SignalR.IHubContext<THub>.Clients.get -> Microsoft.AspNetCore.SignalR.IHubClients!
-*REMOVED*Microsoft.AspNetCore.SignalR.IHubContext<THub>.Groups.get -> Microsoft.AspNetCore.SignalR.IGroupManager!
 Microsoft.AspNetCore.SignalR.IHubContext
 Microsoft.AspNetCore.SignalR.IHubContext.Clients.get -> Microsoft.AspNetCore.SignalR.IHubClients!
 Microsoft.AspNetCore.SignalR.IHubContext.Groups.get -> Microsoft.AspNetCore.SignalR.IGroupManager!

+ 27 - 27
src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs

@@ -4437,6 +4437,33 @@ namespace Microsoft.AspNetCore.SignalR.Tests
             }
         }
 
+        [Fact]
+        public async Task CanSendThroughIHubContext()
+        {
+            using (StartVerifiableLog())
+            {
+                var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
+                var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
+
+                using var client = new TestClient();
+
+                var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
+
+                // Wait for a connection, or for the endpoint to fail.
+                await client.Connected.OrThrowIfOtherFails(connectionHandlerTask).DefaultTimeout();
+
+                IHubContext context = (IHubContext)serviceProvider.GetRequiredService<IHubContext<MethodHub>>();
+                await context.Clients.All.SendAsync("Send", "test");
+
+                var message = await client.ReadAsync().DefaultTimeout();
+                var invocation = Assert.IsType<InvocationMessage>(message);
+
+                Assert.Single(invocation.Arguments);
+                Assert.Equal("test", invocation.Arguments[0]);
+                Assert.Equal("Send", invocation.Target);
+            }
+        }
+
         [Fact]
         public async Task ConnectionCloseCleansUploadStreams()
         {
@@ -4500,33 +4527,6 @@ namespace Microsoft.AspNetCore.SignalR.Tests
             }
         }
 
-        [Fact]
-        public async Task CanSendThroughIHubContext()
-        {
-            using (StartVerifiableLog())
-            {
-                var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
-                var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
-
-                using var client = new TestClient();
-
-                var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
-
-                // Wait for a connection, or for the endpoint to fail.
-                await client.Connected.OrThrowIfOtherFails(connectionHandlerTask).DefaultTimeout();
-
-                IHubContext context = serviceProvider.GetRequiredService<IHubContext<MethodHub>>();
-                await context.Clients.All.SendAsync("Send", "test");
-
-                var message = await client.ReadAsync().DefaultTimeout();
-                var invocation = Assert.IsType<InvocationMessage>(message);
-
-                Assert.Single(invocation.Arguments);
-                Assert.Equal("test", invocation.Arguments[0]);
-                Assert.Equal("Send", invocation.Target);
-            }
-        }
-
         [Fact]
         public async Task CanSendThroughIHubContextBaseHub()
         {