Discover hub methods at startup time (#503)

* Discover hub methods at startup time
- Errors will show up earlier as a result instead of cryptic
first connect errors.
This commit is contained in:
David Fowler 2017-06-01 09:47:39 -10:00 committed by GitHub
parent 5fa3acfd95
commit d10a6293bd
2 changed files with 44 additions and 1 deletions

View File

@ -10,9 +10,9 @@ namespace Microsoft.AspNetCore.SignalR
{
public static ISocketBuilder UseHub<THub>(this ISocketBuilder socketBuilder) where THub : Hub<IClientProxy>
{
var endpoint = socketBuilder.ApplicationServices.GetRequiredService<HubEndPoint<THub>>();
return socketBuilder.Run(connection =>
{
var endpoint = socketBuilder.ApplicationServices.GetRequiredService<HubEndPoint<THub>>();
return endpoint.OnConnectedAsync(connection);
});
}

View File

@ -0,0 +1,43 @@
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace Microsoft.AspNetCore.SignalR.Tests
{
public class MapSignalRTests
{
[Fact]
public void MapSignalRFailsForInvalidHub()
{
var ex = Assert.Throws<NotSupportedException>(() =>
{
var builder = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSignalR();
})
.Configure(app =>
{
app.UseSignalR(options => options.MapHub<InvalidHub>("overloads"));
})
.Build();
});
Assert.Equal("Duplicate definitions of 'OverloadedMethod'. Overloading is not supported.", ex.Message);
}
private class InvalidHub : Hub
{
public void OverloadedMethod(int num)
{
}
public void OverloadedMethod(string message)
{
}
}
}
}