Add SignalR Marker Service (#1573)
This commit is contained in:
parent
d6178f2482
commit
0b81658850
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Builder
|
namespace Microsoft.AspNetCore.Builder
|
||||||
{
|
{
|
||||||
|
|
@ -10,6 +11,13 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
{
|
{
|
||||||
public static IApplicationBuilder UseSignalR(this IApplicationBuilder app, Action<HubRouteBuilder> configure)
|
public static IApplicationBuilder UseSignalR(this IApplicationBuilder app, Action<HubRouteBuilder> configure)
|
||||||
{
|
{
|
||||||
|
var marker = app.ApplicationServices.GetService(typeof(SignalRMarkerService));
|
||||||
|
if (marker == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unable to find the SignalR service. Please add it by " +
|
||||||
|
"calling 'IServiceCollection.AddSignalR()'.");
|
||||||
|
}
|
||||||
|
|
||||||
app.UseSockets(routes =>
|
app.UseSockets(routes =>
|
||||||
{
|
{
|
||||||
configure(new HubRouteBuilder(routes));
|
configure(new HubRouteBuilder(routes));
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
public static ISignalRBuilder AddSignalR(this IServiceCollection services)
|
public static ISignalRBuilder AddSignalR(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSockets();
|
services.AddSockets();
|
||||||
|
services.AddSingleton<SignalRMarkerService>();
|
||||||
services.AddSingleton<IConfigureOptions<HubOptions>, HubOptionsSetup>();
|
services.AddSingleton<IConfigureOptions<HubOptions>, HubOptionsSetup>();
|
||||||
return services.AddSignalRCore()
|
return services.AddSignalRCore()
|
||||||
.AddJsonProtocol();
|
.AddJsonProtocol();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.DependencyInjection
|
||||||
|
{
|
||||||
|
internal class SignalRMarkerService
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,6 +23,26 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
Assert.Equal("Duplicate definitions of 'OverloadedMethod'. Overloading is not supported.", ex.Message);
|
Assert.Equal("Duplicate definitions of 'OverloadedMethod'. Overloading is not supported.", ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void NotAddingSignalRServiceThrows()
|
||||||
|
{
|
||||||
|
var t = new WebHostBuilder()
|
||||||
|
.UseKestrel()
|
||||||
|
.Configure(app =>
|
||||||
|
{
|
||||||
|
var ex = Assert.Throws<InvalidOperationException>(() => {
|
||||||
|
app.UseSignalR(options =>
|
||||||
|
{
|
||||||
|
options.MapHub<AuthHub>("/overloads");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.Equal("Unable to find the SignalR service. Please add it by calling 'IServiceCollection.AddSignalR()'.", ex.Message);
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MapHubFindsAuthAttributeOnHub()
|
public void MapHubFindsAuthAttributeOnHub()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue