question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[SignalR] Strongly-typed Hub Proxies

See original GitHub issue

Edits 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:open
  • Created 4 years ago
  • Reactions:33
  • Comments:35 (19 by maintainers)

github_iconTop GitHub Comments

13reactions
oisingcommented, Jun 29, 2020

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! 😃

10reactions
davidfowlcommented, Sep 19, 2020

We’d likely be looking an approach that uses source generators.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET SignalR Hubs API Guide - Server (C#)
The SignalR Hubs API enables you to make remote procedure calls (RPCs) from a server to connected clients and from clients to the...
Read more >
Typed SignalR Clients - Making type-safe real-time ...
For this, we use the existing strongly typed Hub class and implement the IStickyNoteHub interface. StickyNoteHub.cs. public class StickyNoteHub ...
Read more >
SignalR - Javascript Hub Proxies
... SignalR utility generates only server proxy methods. It will not create client methods, even if you have a strongly typed Hub (Client ......
Read more >
SignalR : Invoking Server Methods (non-proxy)
In short, Proxies allow you to see the server side Hub's methods, you don't have any magic string stuff going on as shown...
Read more >
TypedSignalR.Client 3.4.0
C# Source Generator to create strongly typed SignalR clients. ... CreateHubProxy<IHub>(); // Invoke a hub method through hub proxy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found