Skip to content

Commit 6a8ede0

Browse files
authored
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.
1 parent bc6ed02 commit 6a8ede0

File tree

29 files changed

+135
-133
lines changed

29 files changed

+135
-133
lines changed

SignalR.sln

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C4BC
2222
EndProject
2323
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SocketsSample", "samples\SocketsSample\SocketsSample.csproj", "{C4AEAB04-F341-4539-B6C0-52368FB4BF9E}"
2424
EndProject
25-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Sockets", "src\Microsoft.AspNetCore.Sockets\Microsoft.AspNetCore.Sockets.csproj", "{1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}"
26-
EndProject
2725
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6A35B453-52EC-48AF-89CA-D4A69800F131}"
2826
ProjectSection(SolutionItems) = preProject
2927
test\Directory.Build.props = test\Directory.Build.props
@@ -101,10 +99,6 @@ Global
10199
{C4AEAB04-F341-4539-B6C0-52368FB4BF9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
102100
{C4AEAB04-F341-4539-B6C0-52368FB4BF9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
103101
{C4AEAB04-F341-4539-B6C0-52368FB4BF9E}.Release|Any CPU.Build.0 = Release|Any CPU
104-
{1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
105-
{1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}.Debug|Any CPU.Build.0 = Debug|Any CPU
106-
{1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}.Release|Any CPU.ActiveCfg = Release|Any CPU
107-
{1715EA8D-8E13-4ACF-8BCA-57D048E55ED8}.Release|Any CPU.Build.0 = Release|Any CPU
108102
{AAD719D5-5E31-4ED1-A60F-6EB92EFA66D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
109103
{AAD719D5-5E31-4ED1-A60F-6EB92EFA66D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
110104
{AAD719D5-5E31-4ED1-A60F-6EB92EFA66D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -227,7 +221,6 @@ Global
227221
EndGlobalSection
228222
GlobalSection(NestedProjects) = preSolution
229223
{C4AEAB04-F341-4539-B6C0-52368FB4BF9E} = {C4BC9889-B49F-41B6-806B-F84941B2549B}
230-
{1715EA8D-8E13-4ACF-8BCA-57D048E55ED8} = {DA69F624-5398-4884-87E4-B816698CDE65}
231224
{AAD719D5-5E31-4ED1-A60F-6EB92EFA66D9} = {6A35B453-52EC-48AF-89CA-D4A69800F131}
232225
{42E76F87-92B6-45AB-BF07-6B811C0F2CAC} = {DA69F624-5398-4884-87E4-B816698CDE65}
233226
{59319B72-38BE-4041-8E5C-FF6938874CE8} = {DA69F624-5398-4884-87E4-B816698CDE65}

benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubDispatcherBenchmark.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using Microsoft.Extensions.DependencyInjection;
1717
using Microsoft.Extensions.Logging;
1818
using Microsoft.Extensions.Logging.Abstractions;
19-
using DefaultConnectionContext = Microsoft.AspNetCore.Sockets.DefaultConnectionContext;
2019

2120
namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
2221
{
@@ -42,7 +41,7 @@ public void GlobalSetup()
4241

4342
var options = new PipeOptions();
4443
var pair = DuplexPipe.CreateConnectionPair(options, options);
45-
var connection = new DefaultConnectionContext(Guid.NewGuid().ToString(), pair.Transport, pair.Application);
44+
var connection = new Sockets.DefaultConnectionContext(Guid.NewGuid().ToString(), pair.Transport, pair.Application);
4645

4746
_connectionContext = new NoErrorHubConnectionContext(connection, TimeSpan.Zero, NullLoggerFactory.Instance);
4847

benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Core\Microsoft.AspNetCore.SignalR.Core.csproj" />
1010
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Common\Microsoft.AspNetCore.SignalR.Common.csproj" />
1111
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Protocols.MsgPack\Microsoft.AspNetCore.SignalR.Protocols.MsgPack.csproj" />
12-
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Sockets\Microsoft.AspNetCore.Sockets.csproj" />
1312
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetPackageVersion)" />
1413
<PackageReference Include="Microsoft.AspNetCore.BenchmarkRunner.Sources" Version="$(MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion)" />
1514
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" />
15+
<PackageReference Include="Microsoft.Extensions.ValueStopwatch.Sources" Version="$(MicrosoftExtensionsValueStopwatchSourcesPackageVersion)" PrivateAssets="All" />
1616
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
1717
<PackageReference Include="System.Threading.Channels" Version="$(SystemThreadingChannelsPackageVersion)" />
1818
<PackageReference Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsPackageVersion)" />
1919
<PackageReference Include="System.Reactive.Linq" Version="$(SystemReactiveLinqPackageVersion)" />
2020
</ItemGroup>
21-
2221
</Project>

client-ts/FunctionalTests/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void ConfigureServices(IServiceCollection services)
6969
}
7070
};
7171
});
72-
services.AddEndPoint<EchoEndPoint>();
72+
services.AddSingleton<EchoEndPoint>();
7373
}
7474

7575
public void Configure(IApplicationBuilder app, IHostingEnvironment env)

src/Microsoft.AspNetCore.Sockets/ConnectionList.cs renamed to samples/SocialWeather/ConnectionList.cs

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

1010
namespace Microsoft.AspNetCore.Sockets
1111
{
12-
public class ConnectionList : IReadOnlyCollection<ConnectionContext>
12+
internal class ConnectionList : IReadOnlyCollection<ConnectionContext>
1313
{
1414
private readonly ConcurrentDictionary<string, ConnectionContext> _connections = new ConcurrentDictionary<string, ConnectionContext>();
1515

samples/SocialWeather/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void ConfigureServices(IServiceCollection services)
1717
{
1818
services.AddRouting();
1919
services.AddSockets();
20-
services.AddEndPoint<SocialWeatherEndPoint>();
20+
services.AddSingleton<SocialWeatherEndPoint>();
2121
services.AddTransient<PersistentConnectionLifeTimeManager>();
2222
services.AddSingleton(typeof(JsonStreamFormatter<>), typeof(JsonStreamFormatter<>));
2323
services.AddSingleton<PipeWeatherStreamFormatter>();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections;
6+
using System.Collections.Concurrent;
7+
using System.Collections.Generic;
8+
using Microsoft.AspNetCore.Protocols;
9+
10+
namespace Microsoft.AspNetCore.Sockets
11+
{
12+
internal class ConnectionList : IReadOnlyCollection<ConnectionContext>
13+
{
14+
private readonly ConcurrentDictionary<string, ConnectionContext> _connections = new ConcurrentDictionary<string, ConnectionContext>();
15+
16+
public ConnectionContext this[string connectionId]
17+
{
18+
get
19+
{
20+
if (_connections.TryGetValue(connectionId, out var connection))
21+
{
22+
return connection;
23+
}
24+
return null;
25+
}
26+
}
27+
28+
public int Count => _connections.Count;
29+
30+
public void Add(ConnectionContext connection)
31+
{
32+
_connections.TryAdd(connection.ConnectionId, connection);
33+
}
34+
35+
public void Remove(ConnectionContext connection)
36+
{
37+
_connections.TryRemove(connection.ConnectionId, out var dummy);
38+
}
39+
40+
public IEnumerator<ConnectionContext> GetEnumerator()
41+
{
42+
foreach (var item in _connections)
43+
{
44+
yield return item.Value;
45+
}
46+
}
47+
48+
IEnumerator IEnumerable.GetEnumerator()
49+
{
50+
return GetEnumerator();
51+
}
52+
}
53+
}

samples/SocketsSample/EndPoints/MessagesEndPoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace SocketsSample.EndPoints
1313
{
1414
public class MessagesEndPoint : EndPoint
1515
{
16-
public ConnectionList Connections { get; } = new ConnectionList();
16+
private ConnectionList Connections { get; } = new ConnectionList();
1717

1818
public override async Task OnConnectedAsync(ConnectionContext connection)
1919
{

samples/SocketsSample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void ConfigureServices(IServiceCollection services)
4242
});
4343
});
4444

45-
services.AddEndPoint<MessagesEndPoint>();
45+
services.AddSingleton<MessagesEndPoint>();
4646
}
4747

4848
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

src/Microsoft.AspNetCore.SignalR/HttpConnectionContextExtensions.cs

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

77
namespace Microsoft.AspNetCore.SignalR
88
{
9-
public static class HttpConnectionContextExtensions
9+
public static class DefaultConnectionContextExtensions
1010
{
1111
public static HttpContext GetHttpContext(this HubConnectionContext connection)
1212
{

0 commit comments

Comments
 (0)