mrpmorris / Fluxor

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

Question - Singleton #330

Closed djjohnson-net closed 2 years ago

djjohnson-net commented 2 years ago

I have been looking all over to find an example of using Fluxor State as a Singleton. Can someone direct me in the right direction? (I'm using Blazor Server)I would like the state to be shared across the whole app including users. That's why I'm thinking Singleton. Maybe there is a better way with Fluxor? Any suggestions...

mrpmorris commented 2 years ago

opts.WithLifetime(StoreLifetime.Singleton) in services.AddFluxor(opts => .........) will do it

djjohnson-net commented 2 years ago

Thanks for the suggestion. Does that make all the State objects as Singletons? I'm looking for a solution that will allow me to use Scoped and Singletons depending on how I need them to work.

mrpmorris commented 2 years ago

This would make everything a singleton.

Fluxor is supposed to be used for single-user state synchronisation. I wouldn't recommend it for multi-users in this way.

There is a library that I can't currently remember the name of that does a kind of Flux pattern but for server apps. You might get the name if you ask in https://gitter.im/aspnet/Blazor