diff --git a/samples/SocialWeather/Startup.cs b/samples/SocialWeather/Startup.cs index 1166386668..05199cffb4 100644 --- a/samples/SocialWeather/Startup.cs +++ b/samples/SocialWeather/Startup.cs @@ -17,7 +17,7 @@ namespace SocialWeather { services.AddRouting(); services.AddSockets(); - services.AddSingleton(); + services.AddEndPoint(); services.AddTransient(); services.AddSingleton(typeof(JsonStreamFormatter<>), typeof(JsonStreamFormatter<>)); services.AddSingleton(); diff --git a/samples/SocketsSample/Startup.cs b/samples/SocketsSample/Startup.cs index 7ff3639681..8413ab5d12 100644 --- a/samples/SocketsSample/Startup.cs +++ b/samples/SocketsSample/Startup.cs @@ -29,7 +29,7 @@ namespace SocketsSample }); // .AddRedis(); - services.AddSingleton(); + services.AddEndPoint(); services.AddSingleton(); } diff --git a/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs b/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs index d7becbb1dd..6e34c7249c 100644 --- a/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs +++ b/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs @@ -13,6 +13,7 @@ using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.SignalR { @@ -21,9 +22,10 @@ namespace Microsoft.AspNetCore.SignalR public HubEndPoint(HubLifetimeManager lifetimeManager, IHubContext hubContext, InvocationAdapterRegistry registry, + IOptions>> endPointOptions, ILogger> logger, IServiceScopeFactory serviceScopeFactory) - : base(lifetimeManager, hubContext, registry, logger, serviceScopeFactory) + : base(lifetimeManager, hubContext, registry, endPointOptions, logger, serviceScopeFactory) { } } @@ -41,6 +43,7 @@ namespace Microsoft.AspNetCore.SignalR public HubEndPoint(HubLifetimeManager lifetimeManager, IHubContext hubContext, InvocationAdapterRegistry registry, + IOptions>> endPointOptions, ILogger> logger, IServiceScopeFactory serviceScopeFactory) { diff --git a/src/Microsoft.AspNetCore.Sockets/EndPointOptions.cs b/src/Microsoft.AspNetCore.Sockets/EndPointOptions.cs new file mode 100644 index 0000000000..9183f744cb --- /dev/null +++ b/src/Microsoft.AspNetCore.Sockets/EndPointOptions.cs @@ -0,0 +1,12 @@ +// 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.Authorization; + +namespace Microsoft.AspNetCore.Sockets +{ + public class EndPointOptions where TEndPoint : EndPoint + { + public AuthorizationPolicy Policy { get; set; } + } +} diff --git a/src/Microsoft.AspNetCore.Sockets/EndpointDependencyInjectionExtensions.cs b/src/Microsoft.AspNetCore.Sockets/EndpointDependencyInjectionExtensions.cs new file mode 100644 index 0000000000..a83814c326 --- /dev/null +++ b/src/Microsoft.AspNetCore.Sockets/EndpointDependencyInjectionExtensions.cs @@ -0,0 +1,28 @@ +// 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; + } + + public static IServiceCollection AddEndPoint(this IServiceCollection services, + Action> setupAction) where TEndPoint : EndPoint + { + services.AddEndPoint(); + + services.Configure(setupAction); + + return services; + } + } +} diff --git a/src/Microsoft.AspNetCore.Sockets/Microsoft.AspNetCore.Sockets.csproj b/src/Microsoft.AspNetCore.Sockets/Microsoft.AspNetCore.Sockets.csproj index 7f7d7e0480..ee57b2968a 100644 --- a/src/Microsoft.AspNetCore.Sockets/Microsoft.AspNetCore.Sockets.csproj +++ b/src/Microsoft.AspNetCore.Sockets/Microsoft.AspNetCore.Sockets.csproj @@ -14,9 +14,10 @@ + - + diff --git a/test/Microsoft.AspNetCore.SignalR.Test.Server/Startup.cs b/test/Microsoft.AspNetCore.SignalR.Test.Server/Startup.cs index 29df688410..74f25c6f26 100644 --- a/test/Microsoft.AspNetCore.SignalR.Test.Server/Startup.cs +++ b/test/Microsoft.AspNetCore.SignalR.Test.Server/Startup.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.SignalR.Test.Server { services.AddSockets(); services.AddSignalR(); - services.AddSingleton(); + services.AddEndPoint(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/ServerFixture.cs b/test/Microsoft.AspNetCore.SignalR.Tests/ServerFixture.cs index bb517ac7ea..d696b2b2ab 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/ServerFixture.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/ServerFixture.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests { services.AddSockets(); services.AddSignalR(); - services.AddSingleton(); + services.AddEndPoint(); } 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 da7b4ff3e9..a8887aaf4c 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var dispatcher = new HttpConnectionDispatcher(manager, new LoggerFactory()); var context = new DefaultHttpContext(); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddEndPoint(); context.RequestServices = services.BuildServiceProvider(); var ms = new MemoryStream(); context.Request.Path = "/negotiate"; @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); - services.AddSingleton(); + services.AddEndPoint(); context.RequestServices = services.BuildServiceProvider(); context.Request.Path = path; var values = new Dictionary(); @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = new DefaultHttpContext(); context.Response.Body = strm; var services = new ServiceCollection(); - services.AddSingleton(); + services.AddEndPoint(); context.RequestServices = services.BuildServiceProvider(); context.Request.Path = path; @@ -318,7 +318,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests { var context = new DefaultHttpContext(); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddEndPoint(); context.RequestServices = services.BuildServiceProvider(); context.Request.Path = path; var values = new Dictionary();