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