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:
parent
5fa3acfd95
commit
d10a6293bd
|
|
@ -10,9 +10,9 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
{
|
{
|
||||||
public static ISocketBuilder UseHub<THub>(this ISocketBuilder socketBuilder) where THub : Hub<IClientProxy>
|
public static ISocketBuilder UseHub<THub>(this ISocketBuilder socketBuilder) where THub : Hub<IClientProxy>
|
||||||
{
|
{
|
||||||
|
var endpoint = socketBuilder.ApplicationServices.GetRequiredService<HubEndPoint<THub>>();
|
||||||
return socketBuilder.Run(connection =>
|
return socketBuilder.Run(connection =>
|
||||||
{
|
{
|
||||||
var endpoint = socketBuilder.ApplicationServices.GetRequiredService<HubEndPoint<THub>>();
|
|
||||||
return endpoint.OnConnectedAsync(connection);
|
return endpoint.OnConnectedAsync(connection);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue