mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.25k stars 144 forks source link

Feature/Question: Static/Singleton State #267

Closed JourdanClark closed 2 years ago

JourdanClark commented 2 years ago

Hello,

I have a use case where I have some states which should essentially be static and shared across sessions. This would majorly reduce overhead and improve performance. If I have 10 connections to my Blazor application, I would like all of them to be interacting with the same state instance. Ideally, I would like to initialize this state object on the backend and update it from the server even when no active connections are present, while also allowing active connections to update the state.

I saw in an old Reddit post that .UseSingletonDependencyInjection() was added to 3.9.0-beta-1, but I'm not seeing that in the current version.

Is it possible to do what I'm looking for, or should I come up with another approach?

Note: Not all states should be static.

Thanks

ashern commented 2 years ago

I'd just register a singleton service for that kind of functionality.

services.AddSingleton<MyService>()

You can then inject that into effects and whatnot.

mrpmorris commented 2 years ago

I think I removed it, but I don't recall why. Someone is in the process of creating a PR that will enable you to register everything as Singleton instead of Scoped. The primary purpose of this is for MAUI apps. It would work in multi-user scenarios too, but you'd be sharing everything Fluxor related.