From 6a8ede07701c82bbebb91d55a6d1dc5a42b129ee Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 14 Mar 2018 15:37:24 -0700 Subject: [PATCH] Further making Microsoft.AspNetCore.Sockets "not a thing" (#1599) - This PR attempts to move things where they are needed instead of where they happened to be used. As a result we should now have Sockets.Abstractions and Sockets down to the minimal set of things required to make them run. Sockets.Abstractions should go away in favor of Protocol.Abstractions and Sockets contains the EndPoint abstraction and related types. - Moved ConnectionManager and friends to Sockets.Http. -Removed Sockets and moved everything into Sockets.Abstractions. - Moved DefaultConnection and put it in Sockets.Abstractions. --- SignalR.sln | 7 -- .../DefaultHubDispatcherBenchmark.cs | 3 +- ....AspNetCore.SignalR.Microbenchmarks.csproj | 3 +- client-ts/FunctionalTests/Startup.cs | 2 +- .../SocialWeather}/ConnectionList.cs | 2 +- samples/SocialWeather/Startup.cs | 2 +- samples/SocketsSample/ConnectionList.cs | 53 +++++++++++++++ .../EndPoints/MessagesEndPoint.cs | 2 +- samples/SocketsSample/Startup.cs | 2 +- .../HttpConnectionContextExtensions.cs | 2 +- .../ConnectionBuilderExtensions.cs | 9 ++- .../ConnectionMetadata.cs | 0 .../DefaultConnectionContext.cs | 2 - .../EndPoint.cs | 0 .../ConnectionManager.cs | 37 ++++++----- .../HttpConnectionContextExtensions.cs | 2 +- .../Internal/SocketEventSource.cs | 0 .../Internal/SocketLoggerExtensions.cs | 0 .../Microsoft.AspNetCore.Sockets.Http.csproj | 3 +- .../SocketsDependencyInjectionExtensions.cs | 3 +- .../EndPointDependencyInjectionExtensions.cs | 18 ------ .../Microsoft.AspNetCore.Sockets.csproj | 19 ------ .../SocketsDependencyInjectionExtensions.cs | 17 ----- ...soft.AspNetCore.SignalR.Redis.Tests.csproj | 1 - .../HubConnectionContextUtils.cs | 5 +- ...soft.AspNetCore.SignalR.Tests.Utils.csproj | 4 +- .../Startup.cs | 4 +- .../HttpConnectionDispatcherTests.cs | 64 +++++++++---------- .../MapEndPointTests.cs | 2 +- 29 files changed, 135 insertions(+), 133 deletions(-) rename {src/Microsoft.AspNetCore.Sockets => samples/SocialWeather}/ConnectionList.cs (95%) create mode 100644 samples/SocketsSample/ConnectionList.cs rename src/{Microsoft.AspNetCore.Sockets => Microsoft.AspNetCore.Sockets.Abstractions}/ConnectionBuilderExtensions.cs (68%) rename src/{Microsoft.AspNetCore.Sockets => Microsoft.AspNetCore.Sockets.Abstractions}/ConnectionMetadata.cs (100%) rename src/{Microsoft.AspNetCore.Sockets => Microsoft.AspNetCore.Sockets.Abstractions}/DefaultConnectionContext.cs (98%) rename src/{Microsoft.AspNetCore.Sockets => Microsoft.AspNetCore.Sockets.Abstractions}/EndPoint.cs (100%) rename src/{Microsoft.AspNetCore.Sockets => Microsoft.AspNetCore.Sockets.Http}/ConnectionManager.cs (85%) rename src/{Microsoft.AspNetCore.Sockets => Microsoft.AspNetCore.Sockets.Http}/Internal/SocketEventSource.cs (100%) rename src/{Microsoft.AspNetCore.Sockets => Microsoft.AspNetCore.Sockets.Http}/Internal/SocketLoggerExtensions.cs (100%) delete mode 100644 src/Microsoft.AspNetCore.Sockets/EndPointDependencyInjectionExtensions.cs delete mode 100644 src/Microsoft.AspNetCore.Sockets/Microsoft.AspNetCore.Sockets.csproj delete mode 100644 src/Microsoft.AspNetCore.Sockets/SocketsDependencyInjectionExtensions.cs diff --git a/SignalR.sln b/SignalR.sln index 4f0a69fe76..8372540ece 100644 --- a/SignalR.sln +++ b/SignalR.sln @@ -22,8 +22,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C4BC EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SocketsSample", "samples\SocketsSample\SocketsSample.csproj", "{C4AEAB04-F341-4539-B6C0-52368FB4BF9E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Sockets", "src\Microsoft.AspNetCore.Sockets\Microsoft.AspNetCore.Sockets.csproj", "{1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6A35B453-52EC-48AF-89CA-D4A69800F131}" ProjectSection(SolutionItems) = preProject test\Directory.Build.props = test\Directory.Build.props @@ -101,10 +99,6 @@ Global {C4AEAB04-F341-4539-B6C0-52368FB4BF9E}.Debug|Any CPU.Build.0 = Debug|Any CPU {C4AEAB04-F341-4539-B6C0-52368FB4BF9E}.Release|Any CPU.ActiveCfg = Release|Any CPU {C4AEAB04-F341-4539-B6C0-52368FB4BF9E}.Release|Any CPU.Build.0 = Release|Any CPU - {1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}.Release|Any CPU.Build.0 = Release|Any CPU {AAD719D5-5E31-4ED1-A60F-6EB92EFA66D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AAD719D5-5E31-4ED1-A60F-6EB92EFA66D9}.Debug|Any CPU.Build.0 = Debug|Any CPU {AAD719D5-5E31-4ED1-A60F-6EB92EFA66D9}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -227,7 +221,6 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {C4AEAB04-F341-4539-B6C0-52368FB4BF9E} = {C4BC9889-B49F-41B6-806B-F84941B2549B} - {1715EA8D-8E13-4ACF-8BCA-57D048E55ED8} = {DA69F624-5398-4884-87E4-B816698CDE65} {AAD719D5-5E31-4ED1-A60F-6EB92EFA66D9} = {6A35B453-52EC-48AF-89CA-D4A69800F131} {42E76F87-92B6-45AB-BF07-6B811C0F2CAC} = {DA69F624-5398-4884-87E4-B816698CDE65} {59319B72-38BE-4041-8E5C-FF6938874CE8} = {DA69F624-5398-4884-87E4-B816698CDE65} diff --git a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubDispatcherBenchmark.cs b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubDispatcherBenchmark.cs index e15fbe86dd..5bc73b8aba 100644 --- a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubDispatcherBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubDispatcherBenchmark.cs @@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using DefaultConnectionContext = Microsoft.AspNetCore.Sockets.DefaultConnectionContext; namespace Microsoft.AspNetCore.SignalR.Microbenchmarks { @@ -42,7 +41,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks var options = new PipeOptions(); var pair = DuplexPipe.CreateConnectionPair(options, options); - var connection = new DefaultConnectionContext(Guid.NewGuid().ToString(), pair.Transport, pair.Application); + var connection = new Sockets.DefaultConnectionContext(Guid.NewGuid().ToString(), pair.Transport, pair.Application); _connectionContext = new NoErrorHubConnectionContext(connection, TimeSpan.Zero, NullLoggerFactory.Instance); diff --git a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj index e44c01308b..69db719b11 100644 --- a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj +++ b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj @@ -9,14 +9,13 @@ - + - diff --git a/client-ts/FunctionalTests/Startup.cs b/client-ts/FunctionalTests/Startup.cs index 1af5069f22..982714e46a 100644 --- a/client-ts/FunctionalTests/Startup.cs +++ b/client-ts/FunctionalTests/Startup.cs @@ -69,7 +69,7 @@ namespace FunctionalTests } }; }); - services.AddEndPoint(); + services.AddSingleton(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) diff --git a/src/Microsoft.AspNetCore.Sockets/ConnectionList.cs b/samples/SocialWeather/ConnectionList.cs similarity index 95% rename from src/Microsoft.AspNetCore.Sockets/ConnectionList.cs rename to samples/SocialWeather/ConnectionList.cs index ea3e201c95..870c1fb44e 100644 --- a/src/Microsoft.AspNetCore.Sockets/ConnectionList.cs +++ b/samples/SocialWeather/ConnectionList.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Sockets { - public class ConnectionList : IReadOnlyCollection + internal class ConnectionList : IReadOnlyCollection { private readonly ConcurrentDictionary _connections = new ConcurrentDictionary(); diff --git a/samples/SocialWeather/Startup.cs b/samples/SocialWeather/Startup.cs index 1621ee6a66..2501f09f01 100644 --- a/samples/SocialWeather/Startup.cs +++ b/samples/SocialWeather/Startup.cs @@ -17,7 +17,7 @@ namespace SocialWeather { services.AddRouting(); services.AddSockets(); - services.AddEndPoint(); + services.AddSingleton(); services.AddTransient(); services.AddSingleton(typeof(JsonStreamFormatter<>), typeof(JsonStreamFormatter<>)); services.AddSingleton(); diff --git a/samples/SocketsSample/ConnectionList.cs b/samples/SocketsSample/ConnectionList.cs new file mode 100644 index 0000000000..870c1fb44e --- /dev/null +++ b/samples/SocketsSample/ConnectionList.cs @@ -0,0 +1,53 @@ +// 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; +using System.Collections.Concurrent; +using System.Collections.Generic; +using Microsoft.AspNetCore.Protocols; + +namespace Microsoft.AspNetCore.Sockets +{ + internal class ConnectionList : IReadOnlyCollection + { + private readonly ConcurrentDictionary _connections = new ConcurrentDictionary(); + + public ConnectionContext this[string connectionId] + { + get + { + if (_connections.TryGetValue(connectionId, out var connection)) + { + return connection; + } + return null; + } + } + + public int Count => _connections.Count; + + public void Add(ConnectionContext connection) + { + _connections.TryAdd(connection.ConnectionId, connection); + } + + public void Remove(ConnectionContext connection) + { + _connections.TryRemove(connection.ConnectionId, out var dummy); + } + + public IEnumerator GetEnumerator() + { + foreach (var item in _connections) + { + yield return item.Value; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} diff --git a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs b/samples/SocketsSample/EndPoints/MessagesEndPoint.cs index 5546571b37..7b2c9a7c79 100644 --- a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs +++ b/samples/SocketsSample/EndPoints/MessagesEndPoint.cs @@ -13,7 +13,7 @@ namespace SocketsSample.EndPoints { public class MessagesEndPoint : EndPoint { - public ConnectionList Connections { get; } = new ConnectionList(); + private ConnectionList Connections { get; } = new ConnectionList(); public override async Task OnConnectedAsync(ConnectionContext connection) { diff --git a/samples/SocketsSample/Startup.cs b/samples/SocketsSample/Startup.cs index 76eb958f83..3a59a469be 100644 --- a/samples/SocketsSample/Startup.cs +++ b/samples/SocketsSample/Startup.cs @@ -42,7 +42,7 @@ namespace SocketsSample }); }); - services.AddEndPoint(); + services.AddSingleton(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/src/Microsoft.AspNetCore.SignalR/HttpConnectionContextExtensions.cs b/src/Microsoft.AspNetCore.SignalR/HttpConnectionContextExtensions.cs index 8220822413..3842012f04 100644 --- a/src/Microsoft.AspNetCore.SignalR/HttpConnectionContextExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR/HttpConnectionContextExtensions.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Sockets.Http.Features; namespace Microsoft.AspNetCore.SignalR { - public static class HttpConnectionContextExtensions + public static class DefaultConnectionContextExtensions { public static HttpContext GetHttpContext(this HubConnectionContext connection) { diff --git a/src/Microsoft.AspNetCore.Sockets/ConnectionBuilderExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs similarity index 68% rename from src/Microsoft.AspNetCore.Sockets/ConnectionBuilderExtensions.cs rename to src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs index c2659108aa..cc438b74bc 100644 --- a/src/Microsoft.AspNetCore.Sockets/ConnectionBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs @@ -1,8 +1,8 @@ // 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 Microsoft.AspNetCore.Protocols; -using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Sockets { @@ -10,7 +10,12 @@ namespace Microsoft.AspNetCore.Sockets { public static IConnectionBuilder UseEndPoint(this IConnectionBuilder connectionBuilder) where TEndPoint : EndPoint { - var endpoint = connectionBuilder.ApplicationServices.GetRequiredService(); + var endpoint = (TEndPoint)connectionBuilder.ApplicationServices.GetService(typeof(TEndPoint)); + + if (endpoint == null) + { + throw new InvalidOperationException($"{nameof(EndPoint)} type {typeof(TEndPoint)} is not registered."); + } // This is a terminal middleware, so there's no need to use the 'next' parameter return connectionBuilder.Run(connection => endpoint.OnConnectedAsync(connection)); } diff --git a/src/Microsoft.AspNetCore.Sockets/ConnectionMetadata.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionMetadata.cs similarity index 100% rename from src/Microsoft.AspNetCore.Sockets/ConnectionMetadata.cs rename to src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionMetadata.cs diff --git a/src/Microsoft.AspNetCore.Sockets/DefaultConnectionContext.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/DefaultConnectionContext.cs similarity index 98% rename from src/Microsoft.AspNetCore.Sockets/DefaultConnectionContext.cs rename to src/Microsoft.AspNetCore.Sockets.Abstractions/DefaultConnectionContext.cs index 1a79f5f059..a90c35bf1d 100644 --- a/src/Microsoft.AspNetCore.Sockets/DefaultConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/DefaultConnectionContext.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Protocols.Features; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Sockets { @@ -27,7 +26,6 @@ namespace Microsoft.AspNetCore.Sockets // This tcs exists so that multiple calls to DisposeAsync all wait asynchronously // on the same task private TaskCompletionSource _disposeTcs = new TaskCompletionSource(); - internal ValueStopwatch ConnectionTimer { get; set; } public DefaultConnectionContext(string id, IDuplexPipe transport, IDuplexPipe application) { diff --git a/src/Microsoft.AspNetCore.Sockets/EndPoint.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/EndPoint.cs similarity index 100% rename from src/Microsoft.AspNetCore.Sockets/EndPoint.cs rename to src/Microsoft.AspNetCore.Sockets.Abstractions/EndPoint.cs diff --git a/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs b/src/Microsoft.AspNetCore.Sockets.Http/ConnectionManager.cs similarity index 85% rename from src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs rename to src/Microsoft.AspNetCore.Sockets.Http/ConnectionManager.cs index c9b956fa3a..b04d8e674e 100644 --- a/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/ConnectionManager.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Sockets // TODO: Consider making this configurable? At least for testing? private static readonly TimeSpan _heartbeatTickRate = TimeSpan.FromSeconds(1); - private readonly ConcurrentDictionary _connections = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _connections = new ConcurrentDictionary(); private Timer _timer; private readonly ILogger _logger; private object _executionLock = new object(); @@ -53,7 +53,14 @@ namespace Microsoft.AspNetCore.Sockets public bool TryGetConnection(string id, out DefaultConnectionContext connection) { - return _connections.TryGetValue(id, out connection); + connection = null; + + if (_connections.TryGetValue(id, out var pair)) + { + connection = pair.Connection; + return true; + } + return false; } public DefaultConnectionContext CreateConnection(PipeOptions transportPipeOptions, PipeOptions appPipeOptions) @@ -65,9 +72,8 @@ namespace Microsoft.AspNetCore.Sockets var pair = DuplexPipe.CreateConnectionPair(transportPipeOptions, appPipeOptions); var connection = new DefaultConnectionContext(id, pair.Application, pair.Transport); - connection.ConnectionTimer = connectionTimer; - _connections.TryAdd(id, connection); + _connections.TryAdd(id, (connection, connectionTimer)); return connection; } @@ -78,10 +84,10 @@ namespace Microsoft.AspNetCore.Sockets public void RemoveConnection(string id) { - if (_connections.TryRemove(id, out var connection)) + if (_connections.TryRemove(id, out var pair)) { // Remove the connection completely - SocketEventSource.Log.ConnectionStop(id, connection.ConnectionTimer); + SocketEventSource.Log.ConnectionStop(id, pair.Timer); _logger.RemovedConnection(id); } } @@ -128,33 +134,34 @@ namespace Microsoft.AspNetCore.Sockets { var status = DefaultConnectionContext.ConnectionStatus.Inactive; var lastSeenUtc = DateTimeOffset.UtcNow; + var connection = c.Value.Connection; try { - c.Value.Lock.Wait(); + connection.Lock.Wait(); // Capture the connection state - status = c.Value.Status; + status = connection.Status; - lastSeenUtc = c.Value.LastSeenUtc; + lastSeenUtc = connection.LastSeenUtc; } finally { - c.Value.Lock.Release(); + connection.Lock.Release(); } // Once the decision has been made to dispose we don't check the status again // But don't clean up connections while the debugger is attached. if (!Debugger.IsAttached && status == DefaultConnectionContext.ConnectionStatus.Inactive && (DateTimeOffset.UtcNow - lastSeenUtc).TotalSeconds > 5) { - _logger.ConnectionTimedOut(c.Value.ConnectionId); - SocketEventSource.Log.ConnectionTimedOut(c.Value.ConnectionId); - var ignore = DisposeAndRemoveAsync(c.Value); + _logger.ConnectionTimedOut(connection.ConnectionId); + SocketEventSource.Log.ConnectionTimedOut(connection.ConnectionId); + var ignore = DisposeAndRemoveAsync(connection); } else { // Tick the heartbeat, if the connection is still active - c.Value.TickHeartbeat(); + connection.TickHeartbeat(); } } @@ -191,7 +198,7 @@ namespace Microsoft.AspNetCore.Sockets foreach (var c in _connections) { - tasks.Add(DisposeAndRemoveAsync(c.Value)); + tasks.Add(DisposeAndRemoveAsync(c.Value.Connection)); } Task.WaitAll(tasks.ToArray(), TimeSpan.FromSeconds(5)); diff --git a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs index 8e538d47bf..0118376e34 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Sockets.Http.Features; namespace Microsoft.AspNetCore.Sockets { - public static class HttpConnectionContextExtensions + public static class DefaultConnectionContextExtensions { public static HttpContext GetHttpContext(this ConnectionContext connection) { diff --git a/src/Microsoft.AspNetCore.Sockets/Internal/SocketEventSource.cs b/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketEventSource.cs similarity index 100% rename from src/Microsoft.AspNetCore.Sockets/Internal/SocketEventSource.cs rename to src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketEventSource.cs diff --git a/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketLoggerExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs rename to src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketLoggerExtensions.cs diff --git a/src/Microsoft.AspNetCore.Sockets.Http/Microsoft.AspNetCore.Sockets.Http.csproj b/src/Microsoft.AspNetCore.Sockets.Http/Microsoft.AspNetCore.Sockets.Http.csproj index 1abac737f4..cf115bd037 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/Microsoft.AspNetCore.Sockets.Http.csproj +++ b/src/Microsoft.AspNetCore.Sockets.Http/Microsoft.AspNetCore.Sockets.Http.csproj @@ -12,8 +12,8 @@ - + @@ -22,6 +22,7 @@ + diff --git a/src/Microsoft.AspNetCore.Sockets.Http/SocketsDependencyInjectionExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Http/SocketsDependencyInjectionExtensions.cs index 8b912dcbcb..96c7044ddc 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/SocketsDependencyInjectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/SocketsDependencyInjectionExtensions.cs @@ -13,7 +13,8 @@ namespace Microsoft.Extensions.DependencyInjection services.AddRouting(); services.AddAuthorizationPolicyEvaluator(); services.TryAddSingleton(); - return services.AddSocketsCore(); + services.TryAddSingleton(); + return services; } } } diff --git a/src/Microsoft.AspNetCore.Sockets/EndPointDependencyInjectionExtensions.cs b/src/Microsoft.AspNetCore.Sockets/EndPointDependencyInjectionExtensions.cs deleted file mode 100644 index dfe59a108c..0000000000 --- a/src/Microsoft.AspNetCore.Sockets/EndPointDependencyInjectionExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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 Microsoft.AspNetCore.Sockets; - -namespace Microsoft.Extensions.DependencyInjection -{ - public static class EndPointDependencyInjectionExtensions - { - public static IServiceCollection AddEndPoint(this IServiceCollection services) where TEndPoint : EndPoint - { - services.AddSingleton(); - - return services; - } - } -} diff --git a/src/Microsoft.AspNetCore.Sockets/Microsoft.AspNetCore.Sockets.csproj b/src/Microsoft.AspNetCore.Sockets/Microsoft.AspNetCore.Sockets.csproj deleted file mode 100644 index 50fd3dc4ea..0000000000 --- a/src/Microsoft.AspNetCore.Sockets/Microsoft.AspNetCore.Sockets.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - Components for providing real-time bi-directional communication across the Web. - netstandard2.0 - - - - - - - - - - - - - - diff --git a/src/Microsoft.AspNetCore.Sockets/SocketsDependencyInjectionExtensions.cs b/src/Microsoft.AspNetCore.Sockets/SocketsDependencyInjectionExtensions.cs deleted file mode 100644 index 104f630042..0000000000 --- a/src/Microsoft.AspNetCore.Sockets/SocketsDependencyInjectionExtensions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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.Sockets; -using Microsoft.Extensions.DependencyInjection.Extensions; - -namespace Microsoft.Extensions.DependencyInjection -{ - public static class SocketsDependencyInjectionExtensions - { - public static IServiceCollection AddSocketsCore(this IServiceCollection services) - { - services.TryAddSingleton(); - return services; - } - } -} diff --git a/test/Microsoft.AspNetCore.SignalR.Redis.Tests/Microsoft.AspNetCore.SignalR.Redis.Tests.csproj b/test/Microsoft.AspNetCore.SignalR.Redis.Tests/Microsoft.AspNetCore.SignalR.Redis.Tests.csproj index 0b668c4efb..35cc000165 100644 --- a/test/Microsoft.AspNetCore.SignalR.Redis.Tests/Microsoft.AspNetCore.SignalR.Redis.Tests.csproj +++ b/test/Microsoft.AspNetCore.SignalR.Redis.Tests/Microsoft.AspNetCore.SignalR.Redis.Tests.csproj @@ -14,7 +14,6 @@ - diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/HubConnectionContextUtils.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/HubConnectionContextUtils.cs index 8d1f8dba54..88558e705b 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/HubConnectionContextUtils.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/HubConnectionContextUtils.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; using Microsoft.AspNetCore.Sockets; @@ -12,7 +13,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests { public static class HubConnectionContextUtils { - public static HubConnectionContext Create(DefaultConnectionContext connection) + public static HubConnectionContext Create(ConnectionContext connection) { return new HubConnectionContext(connection, TimeSpan.FromSeconds(15), NullLoggerFactory.Instance) { @@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests }; } - public static Mock CreateMock(DefaultConnectionContext connection) + public static Mock CreateMock(ConnectionContext connection) { var mock = new Mock(connection, TimeSpan.FromSeconds(15), NullLoggerFactory.Instance) { CallBase = true }; var protocol = new JsonHubProtocol(); diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/Microsoft.AspNetCore.SignalR.Tests.Utils.csproj b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/Microsoft.AspNetCore.SignalR.Tests.Utils.csproj index 1e12b690f7..d0c47a6711 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/Microsoft.AspNetCore.SignalR.Tests.Utils.csproj +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/Microsoft.AspNetCore.SignalR.Tests.Utils.csproj @@ -4,15 +4,15 @@ $(StandardTestTfms) Microsoft.AspNetCore.SignalR.Tests - + - + diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs b/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs index eba9d19966..cc98454e11 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests { services.AddSockets(); services.AddSignalR(); - services.AddEndPoint(); - services.AddEndPoint(); + services.AddSingleton(); + services.AddSingleton(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs index 71dcbec08c..d23058c11b 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory); var context = new DefaultHttpContext(); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); services.AddOptions(); var ms = new MemoryStream(); context.Request.Path = "/foo"; @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory); var context = new DefaultHttpContext(); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); services.AddOptions(); var ms = new MemoryStream(); context.Request.Path = "/foo"; @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = responseBody; var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "POST"; @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = new DefaultHttpContext(); context.Features.Set(new ResponseFeature()); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); services.AddOptions(); var ms = new MemoryStream(); context.Request.Path = "/foo"; @@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "GET"; @@ -229,7 +229,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "POST"; @@ -266,7 +266,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "POST"; @@ -311,7 +311,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = responseBody; var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "POST"; @@ -349,7 +349,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); services.AddOptions(); - services.AddEndPoint(); + services.AddSingleton(); context.Request.Path = "/foo"; context.Request.Method = "GET"; @@ -380,7 +380,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); services.AddOptions(); - services.AddEndPoint(); + services.AddSingleton(); context.Request.Path = "/foo"; context.Request.Method = "POST"; @@ -456,7 +456,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, TransportType.ServerSentEvents); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -482,7 +482,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, TransportType.ServerSentEvents); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -508,7 +508,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -534,7 +534,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -560,7 +560,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, TransportType.WebSockets); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -592,7 +592,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context2, transportType); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -631,7 +631,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context2 = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -669,7 +669,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, transportType); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -694,7 +694,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -729,7 +729,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, TransportType.ServerSentEvents); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -762,7 +762,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -793,7 +793,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -837,7 +837,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, transportType); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -865,7 +865,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = new DefaultHttpContext(); var services = new ServiceCollection(); services.AddOptions(); - services.AddEndPoint(); + services.AddSingleton(); services.AddAuthorizationPolicyEvaluator(); services.AddAuthorization(o => { @@ -910,7 +910,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = new DefaultHttpContext(); var services = new ServiceCollection(); services.AddOptions(); - services.AddEndPoint(); + services.AddSingleton(); services.AddAuthorizationPolicyEvaluator(); services.AddAuthorization(o => { @@ -958,7 +958,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Features.Set(new ResponseFeature()); var services = new ServiceCollection(); services.AddOptions(); - services.AddEndPoint(); + services.AddSingleton(); services.AddAuthorizationPolicyEvaluator(); services.AddAuthorization(o => { @@ -1014,7 +1014,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Features.Set(new ResponseFeature()); var services = new ServiceCollection(); services.AddOptions(); - services.AddEndPoint(); + services.AddSingleton(); services.AddAuthorizationPolicyEvaluator(); services.AddAuthorization(o => { @@ -1095,7 +1095,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Features.Set(new ResponseFeature()); var services = new ServiceCollection(); services.AddOptions(); - services.AddEndPoint(); + services.AddSingleton(); services.AddAuthorization(o => { o.AddPolicy("test", policy => @@ -1151,7 +1151,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = new DefaultHttpContext(); var services = new ServiceCollection(); services.AddOptions(); - services.AddEndPoint(); + services.AddSingleton(); services.AddAuthorization(o => { o.AddPolicy("test", policy => @@ -1206,7 +1206,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddEndPoint(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -1278,7 +1278,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); services.AddOptions(); - services.AddEndPoint(); + services.AddSingleton(); SetTransport(context, transportType); context.Request.Path = "/foo"; context.Request.Method = "GET"; @@ -1305,7 +1305,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests } } - private static DefaultHttpContext MakeRequest(string path, DefaultConnectionContext connection, string format = null) + private static DefaultHttpContext MakeRequest(string path, ConnectionContext connection, string format = null) { var context = new DefaultHttpContext(); context.Features.Set(new ResponseFeature()); diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs index 0854c338ff..10203d3ae0 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs @@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests .ConfigureServices(services => { services.AddSockets(); - services.AddEndPoint(); + services.AddSingleton(); }) .Configure(app => {