From c8b6bb3f419b3c2065662fc40e27769f132310de Mon Sep 17 00:00:00 2001
From: Brennan <brecon@microsoft.com>
Date: Wed, 17 Jul 2019 16:54:31 -0700
Subject: [PATCH] Update SignalR Endpoint pattern usage (#12282)

---
 ...NetCore.Components.Server.netcoreapp3.0.cs |  2 +-
 .../ComponentEndpointConventionBuilder.cs     |  1 -
 ...nentEndpointConventionBuilderExtensions.cs |  1 -
 ...pNetCore.Http.Connections.netcoreapp3.0.cs | 13 ++++++---
 .../src/ConnectionEndpointRouteBuilder.cs     | 29 +++++++++++++++++++
 ...onnectionEndpointRouteBuilderExtensions.cs | 18 ++++++------
 ...rosoft.AspNetCore.SignalR.netcoreapp3.0.cs | 20 ++++++-------
 .../src/HubEndpointConventionBuilder.cs       |  3 +-
 .../src/IHubEndpointConventionBuilder.cs      |  7 ++---
 9 files changed, 61 insertions(+), 33 deletions(-)
 create mode 100644 src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilder.cs

diff --git a/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp3.0.cs b/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp3.0.cs
index 08dee32743b..e39c5d64acf 100644
--- a/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp3.0.cs
+++ b/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp3.0.cs
@@ -3,7 +3,7 @@
 
 namespace Microsoft.AspNetCore.Builder
 {
-    public sealed partial class ComponentEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder, Microsoft.AspNetCore.SignalR.IHubEndpointConventionBuilder
+    public sealed partial class ComponentEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder, Microsoft.AspNetCore.Builder.IHubEndpointConventionBuilder
     {
         internal ComponentEndpointConventionBuilder() { }
         public void Add(System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder> convention) { }
diff --git a/src/Components/Server/src/Builder/ComponentEndpointConventionBuilder.cs b/src/Components/Server/src/Builder/ComponentEndpointConventionBuilder.cs
index 150e373a233..021272c7d67 100644
--- a/src/Components/Server/src/Builder/ComponentEndpointConventionBuilder.cs
+++ b/src/Components/Server/src/Builder/ComponentEndpointConventionBuilder.cs
@@ -2,7 +2,6 @@
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
 using System;
-using Microsoft.AspNetCore.SignalR;
 
 namespace Microsoft.AspNetCore.Builder
 {
diff --git a/src/Components/Server/src/Builder/ComponentEndpointConventionBuilderExtensions.cs b/src/Components/Server/src/Builder/ComponentEndpointConventionBuilderExtensions.cs
index 0a29e1790dc..b7d260d25eb 100644
--- a/src/Components/Server/src/Builder/ComponentEndpointConventionBuilderExtensions.cs
+++ b/src/Components/Server/src/Builder/ComponentEndpointConventionBuilderExtensions.cs
@@ -4,7 +4,6 @@
 using System;
 using System.Collections.Generic;
 using Microsoft.AspNetCore.Components.Server;
-using Microsoft.AspNetCore.SignalR;
 
 namespace Microsoft.AspNetCore.Builder
 {
diff --git a/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp3.0.cs b/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp3.0.cs
index 64b628f6a43..7810a4985d7 100644
--- a/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp3.0.cs
+++ b/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp3.0.cs
@@ -3,12 +3,17 @@
 
 namespace Microsoft.AspNetCore.Builder
 {
+    public sealed partial class ConnectionEndpointRouteBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
+    {
+        internal ConnectionEndpointRouteBuilder() { }
+        public void Add(System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder> convention) { }
+    }
     public static partial class ConnectionEndpointRouteBuilderExtensions
     {
-        public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapConnectionHandler<TConnectionHandler>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern) where TConnectionHandler : Microsoft.AspNetCore.Connections.ConnectionHandler { throw null; }
-        public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapConnectionHandler<TConnectionHandler>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where TConnectionHandler : Microsoft.AspNetCore.Connections.ConnectionHandler { throw null; }
-        public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapConnections(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions options, System.Action<Microsoft.AspNetCore.Connections.IConnectionBuilder> configure) { throw null; }
-        public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapConnections(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action<Microsoft.AspNetCore.Connections.IConnectionBuilder> configure) { throw null; }
+        public static Microsoft.AspNetCore.Builder.ConnectionEndpointRouteBuilder MapConnectionHandler<TConnectionHandler>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern) where TConnectionHandler : Microsoft.AspNetCore.Connections.ConnectionHandler { throw null; }
+        public static Microsoft.AspNetCore.Builder.ConnectionEndpointRouteBuilder MapConnectionHandler<TConnectionHandler>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where TConnectionHandler : Microsoft.AspNetCore.Connections.ConnectionHandler { throw null; }
+        public static Microsoft.AspNetCore.Builder.ConnectionEndpointRouteBuilder MapConnections(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions options, System.Action<Microsoft.AspNetCore.Connections.IConnectionBuilder> configure) { throw null; }
+        public static Microsoft.AspNetCore.Builder.ConnectionEndpointRouteBuilder MapConnections(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action<Microsoft.AspNetCore.Connections.IConnectionBuilder> configure) { throw null; }
     }
     public static partial class ConnectionsAppBuilderExtensions
     {
diff --git a/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilder.cs b/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilder.cs
new file mode 100644
index 00000000000..3c8a57c0cd7
--- /dev/null
+++ b/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilder.cs
@@ -0,0 +1,29 @@
+// 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;
+
+namespace Microsoft.AspNetCore.Builder
+{
+    /// <summary>
+    /// Builds conventions that will be used for customization of Connection <see cref="EndpointBuilder"/> instances.
+    /// </summary>
+    public sealed class ConnectionEndpointRouteBuilder : IEndpointConventionBuilder
+    {
+        private readonly IEndpointConventionBuilder _endpointConventionBuilder;
+
+        internal ConnectionEndpointRouteBuilder(IEndpointConventionBuilder endpointConventionBuilder)
+        {
+            _endpointConventionBuilder = endpointConventionBuilder;
+        }
+
+        /// <summary>
+        /// Adds the specified convention to the builder. Conventions are used to customize <see cref="EndpointBuilder"/> instances.
+        /// </summary>
+        /// <param name="convention">The convention to add to the builder.</param>
+        public void Add(Action<EndpointBuilder> convention)
+        {
+            _endpointConventionBuilder.Add(convention);
+        }
+    }
+}
diff --git a/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs b/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs
index 7833a466008..97ba2b3c0e9 100644
--- a/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs
+++ b/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs
@@ -19,8 +19,8 @@ namespace Microsoft.AspNetCore.Builder
         /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
         /// <param name="pattern">The route pattern.</param>
         /// <param name="configure">A callback to configure the connection.</param>
-        /// <returns>An <see cref="IEndpointConventionBuilder"/> for endpoints associated with the connections.</returns>
-        public static IEndpointConventionBuilder MapConnections(this IEndpointRouteBuilder endpoints, string pattern, Action<IConnectionBuilder> configure) =>
+        /// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns>
+        public static ConnectionEndpointRouteBuilder MapConnections(this IEndpointRouteBuilder endpoints, string pattern, Action<IConnectionBuilder> configure) =>
             endpoints.MapConnections(pattern, new HttpConnectionDispatcherOptions(), configure);
 
         /// <summary>
@@ -29,8 +29,8 @@ namespace Microsoft.AspNetCore.Builder
         /// <typeparam name="TConnectionHandler">The <see cref="ConnectionHandler"/> type.</typeparam>
         /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
         /// <param name="pattern">The route pattern.</param>
-        /// <returns>An <see cref="IEndpointConventionBuilder"/> for endpoints associated with the connections.</returns>
-        public static IEndpointConventionBuilder MapConnectionHandler<TConnectionHandler>(this IEndpointRouteBuilder endpoints, string pattern) where TConnectionHandler : ConnectionHandler
+        /// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns>
+        public static ConnectionEndpointRouteBuilder MapConnectionHandler<TConnectionHandler>(this IEndpointRouteBuilder endpoints, string pattern) where TConnectionHandler : ConnectionHandler
         {
             return endpoints.MapConnectionHandler<TConnectionHandler>(pattern, configureOptions: null);
         }
@@ -42,8 +42,8 @@ namespace Microsoft.AspNetCore.Builder
         /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
         /// <param name="pattern">The route pattern.</param>
         /// <param name="configureOptions">A callback to configure dispatcher options.</param>
-        /// <returns>An <see cref="IEndpointConventionBuilder"/> for endpoints associated with the connections.</returns>
-        public static IEndpointConventionBuilder MapConnectionHandler<TConnectionHandler>(this IEndpointRouteBuilder endpoints, string pattern, Action<HttpConnectionDispatcherOptions> configureOptions) where TConnectionHandler : ConnectionHandler
+        /// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns>
+        public static ConnectionEndpointRouteBuilder MapConnectionHandler<TConnectionHandler>(this IEndpointRouteBuilder endpoints, string pattern, Action<HttpConnectionDispatcherOptions> configureOptions) where TConnectionHandler : ConnectionHandler
         {
             var options = new HttpConnectionDispatcherOptions();
             configureOptions?.Invoke(options);
@@ -75,8 +75,8 @@ namespace Microsoft.AspNetCore.Builder
         /// <param name="pattern">The route pattern.</param>
         /// <param name="options">Options used to configure the connection.</param>
         /// <param name="configure">A callback to configure the connection.</param>
-        /// <returns>An <see cref="IEndpointConventionBuilder"/> for endpoints associated with the connections.</returns>
-        public static IEndpointConventionBuilder MapConnections(this IEndpointRouteBuilder endpoints, string pattern, HttpConnectionDispatcherOptions options, Action<IConnectionBuilder> configure)
+        /// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns>
+        public static ConnectionEndpointRouteBuilder MapConnections(this IEndpointRouteBuilder endpoints, string pattern, HttpConnectionDispatcherOptions options, Action<IConnectionBuilder> configure)
         {
             var dispatcher = endpoints.ServiceProvider.GetRequiredService<HttpConnectionDispatcher>();
 
@@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Builder
                 }
             });
 
-            return compositeConventionBuilder;
+            return new ConnectionEndpointRouteBuilder(compositeConventionBuilder);
         }
 
         private class CompositeEndpointConventionBuilder : IEndpointConventionBuilder
diff --git a/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp3.0.cs b/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp3.0.cs
index 56b62a7317e..0021c03cbd8 100644
--- a/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp3.0.cs
+++ b/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp3.0.cs
@@ -3,10 +3,18 @@
 
 namespace Microsoft.AspNetCore.Builder
 {
+    public sealed partial class HubEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder, Microsoft.AspNetCore.Builder.IHubEndpointConventionBuilder
+    {
+        internal HubEndpointConventionBuilder() { }
+        public void Add(System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder> convention) { }
+    }
     public static partial class HubEndpointRouteBuilderExtensions
     {
-        public static Microsoft.AspNetCore.SignalR.HubEndpointConventionBuilder MapHub<THub>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern) where THub : Microsoft.AspNetCore.SignalR.Hub { throw null; }
-        public static Microsoft.AspNetCore.SignalR.HubEndpointConventionBuilder MapHub<THub>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where THub : Microsoft.AspNetCore.SignalR.Hub { throw null; }
+        public static Microsoft.AspNetCore.Builder.HubEndpointConventionBuilder MapHub<THub>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern) where THub : Microsoft.AspNetCore.SignalR.Hub { throw null; }
+        public static Microsoft.AspNetCore.Builder.HubEndpointConventionBuilder MapHub<THub>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where THub : Microsoft.AspNetCore.SignalR.Hub { throw null; }
+    }
+    public partial interface IHubEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
+    {
     }
     public static partial class SignalRAppBuilderExtensions
     {
@@ -21,11 +29,6 @@ namespace Microsoft.AspNetCore.SignalR
         public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.SignalR.HubCallerContext connection) { throw null; }
         public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.SignalR.HubConnectionContext connection) { throw null; }
     }
-    public sealed partial class HubEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder, Microsoft.AspNetCore.SignalR.IHubEndpointConventionBuilder
-    {
-        internal HubEndpointConventionBuilder() { }
-        public void Add(System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder> convention) { }
-    }
     [System.ObsoleteAttribute("This class is obsolete and will be removed in a future version. The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")]
     public partial class HubRouteBuilder
     {
@@ -33,9 +36,6 @@ namespace Microsoft.AspNetCore.SignalR
         public void MapHub<THub>(Microsoft.AspNetCore.Http.PathString path) where THub : Microsoft.AspNetCore.SignalR.Hub { }
         public void MapHub<THub>(Microsoft.AspNetCore.Http.PathString path, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where THub : Microsoft.AspNetCore.SignalR.Hub { }
     }
-    public partial interface IHubEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
-    {
-    }
 }
 namespace Microsoft.Extensions.DependencyInjection
 {
diff --git a/src/SignalR/server/SignalR/src/HubEndpointConventionBuilder.cs b/src/SignalR/server/SignalR/src/HubEndpointConventionBuilder.cs
index fc2cd2cca03..54be9a6ea71 100644
--- a/src/SignalR/server/SignalR/src/HubEndpointConventionBuilder.cs
+++ b/src/SignalR/server/SignalR/src/HubEndpointConventionBuilder.cs
@@ -2,9 +2,8 @@
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
 using System;
-using Microsoft.AspNetCore.Builder;
 
-namespace Microsoft.AspNetCore.SignalR
+namespace Microsoft.AspNetCore.Builder
 {
     /// <summary>
     /// Builds conventions that will be used for customization of Hub <see cref="EndpointBuilder"/> instances.
diff --git a/src/SignalR/server/SignalR/src/IHubEndpointConventionBuilder.cs b/src/SignalR/server/SignalR/src/IHubEndpointConventionBuilder.cs
index 141311ccd24..357cbe1ba0e 100644
--- a/src/SignalR/server/SignalR/src/IHubEndpointConventionBuilder.cs
+++ b/src/SignalR/server/SignalR/src/IHubEndpointConventionBuilder.cs
@@ -1,15 +1,12 @@
-// Copyright (c) .NET Foundation. All rights reserved.
+// 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 Microsoft.AspNetCore.Builder;
-
-namespace Microsoft.AspNetCore.SignalR
+namespace Microsoft.AspNetCore.Builder
 {
     /// <summary>
     /// Abstraction that builds conventions that will be used for customization of Hub <see cref="EndpointBuilder"/> instances.
     /// </summary>
     public interface IHubEndpointConventionBuilder : IEndpointConventionBuilder
     {
-
     }
 }
-- 
GitLab