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.
This commit is contained in:
David Fowler 2018-03-14 15:37:24 -07:00 committed by GitHub
parent bc6ed02b6e
commit 6a8ede0770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 135 additions and 133 deletions

View File

@ -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}

View File

@ -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);

View File

@ -9,14 +9,13 @@
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Core\Microsoft.AspNetCore.SignalR.Core.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Common\Microsoft.AspNetCore.SignalR.Common.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Protocols.MsgPack\Microsoft.AspNetCore.SignalR.Protocols.MsgPack.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Sockets\Microsoft.AspNetCore.Sockets.csproj" />
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.BenchmarkRunner.Sources" Version="$(MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.ValueStopwatch.Sources" Version="$(MicrosoftExtensionsValueStopwatchSourcesPackageVersion)" PrivateAssets="All" />
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
<PackageReference Include="System.Threading.Channels" Version="$(SystemThreadingChannelsPackageVersion)" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsPackageVersion)" />
<PackageReference Include="System.Reactive.Linq" Version="$(SystemReactiveLinqPackageVersion)" />
</ItemGroup>
</Project>

View File

@ -69,7 +69,7 @@ namespace FunctionalTests
}
};
});
services.AddEndPoint<EchoEndPoint>();
services.AddSingleton<EchoEndPoint>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)

View File

@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Protocols;
namespace Microsoft.AspNetCore.Sockets
{
public class ConnectionList : IReadOnlyCollection<ConnectionContext>
internal class ConnectionList : IReadOnlyCollection<ConnectionContext>
{
private readonly ConcurrentDictionary<string, ConnectionContext> _connections = new ConcurrentDictionary<string, ConnectionContext>();

View File

@ -17,7 +17,7 @@ namespace SocialWeather
{
services.AddRouting();
services.AddSockets();
services.AddEndPoint<SocialWeatherEndPoint>();
services.AddSingleton<SocialWeatherEndPoint>();
services.AddTransient<PersistentConnectionLifeTimeManager>();
services.AddSingleton(typeof(JsonStreamFormatter<>), typeof(JsonStreamFormatter<>));
services.AddSingleton<PipeWeatherStreamFormatter>();

View File

@ -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<ConnectionContext>
{
private readonly ConcurrentDictionary<string, ConnectionContext> _connections = new ConcurrentDictionary<string, ConnectionContext>();
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<ConnectionContext> GetEnumerator()
{
foreach (var item in _connections)
{
yield return item.Value;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@ -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)
{

View File

@ -42,7 +42,7 @@ namespace SocketsSample
});
});
services.AddEndPoint<MessagesEndPoint>();
services.AddSingleton<MessagesEndPoint>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

View File

@ -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)
{

View File

@ -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<TEndPoint>(this IConnectionBuilder connectionBuilder) where TEndPoint : EndPoint
{
var endpoint = connectionBuilder.ApplicationServices.GetRequiredService<TEndPoint>();
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));
}

View File

@ -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<object> _disposeTcs = new TaskCompletionSource<object>();
internal ValueStopwatch ConnectionTimer { get; set; }
public DefaultConnectionContext(string id, IDuplexPipe transport, IDuplexPipe application)
{

View File

@ -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<string, DefaultConnectionContext> _connections = new ConcurrentDictionary<string, DefaultConnectionContext>();
private readonly ConcurrentDictionary<string, (DefaultConnectionContext Connection, ValueStopwatch Timer)> _connections = new ConcurrentDictionary<string, (DefaultConnectionContext Connection, ValueStopwatch Timer)>();
private Timer _timer;
private readonly ILogger<ConnectionManager> _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));

View File

@ -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)
{

View File

@ -12,8 +12,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Sockets\Microsoft.AspNetCore.Sockets.csproj" />
<ProjectReference Include="..\Microsoft.AspNetCore.Sockets.Common.Http\Microsoft.AspNetCore.Sockets.Common.Http.csproj" />
<ProjectReference Include="..\Microsoft.AspNetCore.Sockets.Abstractions\Microsoft.AspNetCore.Sockets.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="$(MicrosoftAspNetCoreRoutingPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="$(MicrosoftAspNetCoreWebSocketsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.SecurityHelper.Sources" PrivateAssets="All" Version="$(MicrosoftExtensionsSecurityHelperSourcesPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.ValueStopwatch.Sources" Version="$(MicrosoftExtensionsValueStopwatchSourcesPackageVersion)" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
</ItemGroup>

View File

@ -13,7 +13,8 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddRouting();
services.AddAuthorizationPolicyEvaluator();
services.TryAddSingleton<HttpConnectionDispatcher>();
return services.AddSocketsCore();
services.TryAddSingleton<ConnectionManager>();
return services;
}
}
}

View File

@ -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<TEndPoint>(this IServiceCollection services) where TEndPoint : EndPoint
{
services.AddSingleton<TEndPoint>();
return services;
}
}
}

View File

@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Components for providing real-time bi-directional communication across the Web.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Sockets.Abstractions\Microsoft.AspNetCore.Sockets.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="$(MicrosoftAspNetCoreHostingAbstractionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.ValueStopwatch.Sources" Version="$(MicrosoftExtensionsValueStopwatchSourcesPackageVersion)" PrivateAssets="All" />
</ItemGroup>
</Project>

View File

@ -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<ConnectionManager>();
return services;
}
}
}

View File

@ -14,7 +14,6 @@
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.MsgPack\Microsoft.AspNetCore.SignalR.MsgPack.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Protocols.MsgPack\Microsoft.AspNetCore.SignalR.Protocols.MsgPack.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Redis\Microsoft.AspNetCore.SignalR.Redis.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Sockets\Microsoft.AspNetCore.Sockets.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Client\Microsoft.AspNetCore.SignalR.Client.csproj" />
<ProjectReference Include="..\Microsoft.AspNetCore.SignalR.Tests.Utils\Microsoft.AspNetCore.SignalR.Tests.Utils.csproj" />

View File

@ -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<HubConnectionContext> CreateMock(DefaultConnectionContext connection)
public static Mock<HubConnectionContext> CreateMock(ConnectionContext connection)
{
var mock = new Mock<HubConnectionContext>(connection, TimeSpan.FromSeconds(15), NullLoggerFactory.Instance) { CallBase = true };
var protocol = new JsonHubProtocol();

View File

@ -4,15 +4,15 @@
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
<RootNamespace>Microsoft.AspNetCore.SignalR.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Common\Microsoft.AspNetCore.SignalR.Common.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Core\Microsoft.AspNetCore.SignalR.Core.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Sockets\Microsoft.AspNetCore.Sockets.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(MicrosoftExtensionsLoggingTestingPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.ValueStopwatch.Sources" Version="$(MicrosoftExtensionsValueStopwatchSourcesPackageVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(MicrosoftAspNetCoreHostingPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
</ItemGroup>

View File

@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{
services.AddSockets();
services.AddSignalR();
services.AddEndPoint<EchoEndPoint>();
services.AddEndPoint<HttpHeaderEndPoint>();
services.AddSingleton<EchoEndPoint>();
services.AddSingleton<HttpHeaderEndPoint>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)

View File

@ -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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<IHttpResponseFeature>(new ResponseFeature());
var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<ImmediatelyCompleteEndPoint>();
services.AddSingleton<ImmediatelyCompleteEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
var app = builder.Build();
@ -482,7 +482,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
SetTransport(context, TransportType.ServerSentEvents);
var services = new ServiceCollection();
services.AddEndPoint<SynchronusExceptionEndPoint>();
services.AddSingleton<SynchronusExceptionEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<SynchronusExceptionEndPoint>();
var app = builder.Build();
@ -508,7 +508,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var context = MakeRequest("/foo", connection);
var services = new ServiceCollection();
services.AddEndPoint<ImmediatelyCompleteEndPoint>();
services.AddSingleton<ImmediatelyCompleteEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
var app = builder.Build();
@ -534,7 +534,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var context = MakeRequest("/foo", connection);
var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>();
var app = builder.Build();
@ -560,7 +560,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
SetTransport(context, TransportType.WebSockets);
var services = new ServiceCollection();
services.AddEndPoint<ImmediatelyCompleteEndPoint>();
services.AddSingleton<ImmediatelyCompleteEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
var app = builder.Build();
@ -592,7 +592,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
SetTransport(context2, transportType);
var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>();
var app = builder.Build();
@ -631,7 +631,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var context2 = MakeRequest("/foo", connection);
var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>();
var app = builder.Build();
@ -669,7 +669,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
SetTransport(context, transportType);
var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>();
var app = builder.Build();
@ -694,7 +694,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var context = MakeRequest("/foo", connection);
var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>();
var app = builder.Build();
@ -729,7 +729,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
SetTransport(context, TransportType.ServerSentEvents);
var services = new ServiceCollection();
services.AddEndPoint<BlockingEndPoint>();
services.AddSingleton<BlockingEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<BlockingEndPoint>();
var app = builder.Build();
@ -762,7 +762,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var context = MakeRequest("/foo", connection);
var services = new ServiceCollection();
services.AddEndPoint<BlockingEndPoint>();
services.AddSingleton<BlockingEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<BlockingEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>();
var app = builder.Build();
@ -837,7 +837,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
SetTransport(context, transportType);
var services = new ServiceCollection();
services.AddEndPoint<ImmediatelyCompleteEndPoint>();
services.AddSingleton<ImmediatelyCompleteEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
services.AddAuthorizationPolicyEvaluator();
services.AddAuthorization(o =>
{
@ -958,7 +958,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
var services = new ServiceCollection();
services.AddOptions();
services.AddEndPoint<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
services.AddAuthorizationPolicyEvaluator();
services.AddAuthorization(o =>
{
@ -1014,7 +1014,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
var services = new ServiceCollection();
services.AddOptions();
services.AddEndPoint<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
services.AddAuthorizationPolicyEvaluator();
services.AddAuthorization(o =>
{
@ -1095,7 +1095,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
var services = new ServiceCollection();
services.AddOptions();
services.AddEndPoint<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
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<TestEndPoint>();
services.AddSingleton<TestEndPoint>();
var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>();
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<ImmediatelyCompleteEndPoint>();
services.AddSingleton<ImmediatelyCompleteEndPoint>();
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<IHttpResponseFeature>(new ResponseFeature());

View File

@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
.ConfigureServices(services =>
{
services.AddSockets();
services.AddEndPoint<TEndPoint>();
services.AddSingleton<TEndPoint>();
})
.Configure(app =>
{