dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.22k stars 9.95k forks source link

Server-side Blazor: Consistently push to multiple circuits #17956

Open Trolldemorted opened 4 years ago

Trolldemorted commented 4 years ago

Is your feature request related to a problem? Please describe.

There are several issues that ask about how we should push data to clients (e.g. https://github.com/aspnet/AspNetCore/issues/10559, https://github.com/aspnet/AspNetCore/issues/14778), and none has received a clear response so far.

The absence of documentation and guidance has fostered blogs and demos that propose odd workarounds, such as opening a new, dedicated signalr connection to a dedicated hub from within the circuit or making circuits subscribe and unsubscribe to a public static delegate while praying that everything is correctly disposed.

If I understand @rynowak correctly we could set up a ConcurrentQueue per circuit, have $something fill it, have a background thread drain it, and invoke StateHasChanged. However we are lacking concise instructions on thread safety in server-side blazor (should we update the "model" from the background thread and then just invoke? Does the circuit's "main task" have a synchronization context? Should we pass updated models to the circuit in a special way?), so this is not something I can use to build an app with.

Describe the solution you'd like

The documentation should present a bulletproof scheme that allows us to easily dispatch an event to sets of circuits!

We have to be sure that

I am fairly certain that right now everyone developing a server-side blazor app which provides inter-circuit communication is reinventing the same wheel, and this wheel is at a crucial position in everyone's webapp, and that is awful, because most of those (including me) won't have the required internal knowledge to know the lifecycles and pitfalls of server-side blazor.

If the response is "we won't support that ourselves within the near future, please use a dedicated message broker like redis/whateverMQ" that is completely fine (and reasonable for scale out scenarios), but please provide a reliable minimal example that interested parties can use to build a prototype.

pranavkm commented 4 years ago

Thanks for your issue report. We'll look at getting some samples or guidance added to cover this scenario.

schmitch commented 4 years ago

I mean I think most people probably wan't to stream data to multiple clients, which triggers a rerender without going trough server -> client (javascript signalr or so) -> calls blazor callable js function (which involves a server roundtrip) -> re-render.

I think most people just want something like a IAsyncEnumerable<Data> that multiple "users/circuits" can subscribe to, without going trough the server -> client -> server hop.

mkArtakMSFT commented 4 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

ghost commented 9 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.