[SignalR] Strongly-typed Hub Proxies
See original GitHub issueEdits from @anurse
Let’s use this to track strongly-typed hub proxies all-up. We’ve talked about a few ways of doing it (code-gen, reflection emit, etc.). We have to consider a few things
- Which clients can support it?
- Which client environments can support it (for example, AOT environments like Unity wouldn’t be able to support reflection emit-based generation)?
- What’s the API
- How does this interact with client-side hubs #5278
Original issue follows
On the server side, we can create a strongly-typed hub (docs: https://docs.microsoft.com/en-us/aspnet/core/signalr/hubs?view=aspnetcore-3.0#strongly-typed-hubs). However, on the client-side, everything is still loosely typed, which means we lose type safety. Does the TypeScript client have any support for a strongly-typed connection? I imagine it could use generics on the build
function, eg:
const connection = new HubConnectionBuilder()
.withUrl("/hub")
.build<MyHub>();
My ideal setup would be automatically generating a TypeScript client based on the C# strongly-typed Hub, but for now I’d be fine just manually creating a TypeScript type that replicates the server-side one.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:33
- Comments:35 (19 by maintainers)
It’s been a few years since I’ve used a signalr .net C# client, and I was surprised to find that it’s still all strings and On() buffoonery. I’d love to see a strongly typed client view of the server hub. The symmetry is broken – we cannot have this! 😃
We’d likely be looking an approach that uses source generators.