aspnetcore
aspnetcore copied to clipboard
State management needs to support transition between Server and WebAssembly models in Web Apps
Is there an existing issue for this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
I have a service registered as a singleton that maintains a list of the pages a user has visited in their current session that I use to identify whether some parts of the site should promoted more or less based on their measured interest. I'd like to use the WebAssembly mode of a .NET 8 Web App to reduce load on my server but it occurs to me that as users are transitioned from the Server project to the Client project, they'll effectively be starting over with a new WASM-registered client and lose that data.
While this scenario could just as easily see the data persisted somewhere like local or server storage and recalled during service initialization, that's not always feasible with services that temporarily persist data not intended to be serialized. For example, the Fluxor package provides a Flux/Redux approach to managing state on a single global store, but where it's Store may be initialized on the Server and data persisted to it, the jump to the Client project means that the single state store is lost as it's re-initialized in the new context.
Describe the solution you'd like
Ideally, rather than having a separate DI registration for server and client, I'd like to see the client be able to inherit select registrations from the server so that as this transition happens, the current service state can be cloned into the client as though nothing ever happened. How that happens though, no idea.
In lieu of that, some sort of channel to call a method on the service in the other context and provide a class/record with the current state so I could pre-seed it would be helpful (this would need to be bi-directional so both contexts could stay in sync).
Ideally, just something that ensure that no matter the content
Additional context
Please consider adding another tab with recommendations of how to approach this to the state management documentation. Right now, it's not very helpful for those trying to solve State Management with the latest Web App template.
@WhitWaldo thanks for contacting us.
This is already possible. For a sample that does something similar to what you are looking for see https://github.com/javiercn/BlazorWebNonceService
In essence, your service can persist the current server state and reading during app startup in interactiveserver/interactivewebassembly
Hi @WhitWaldo. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
See our Issue Management Policies for more information.