mrpmorris / Fluxor

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

FluxorOptions.AfterScan callback #401

Open mrpmorris opened 1 year ago

mrpmorris commented 1 year ago

Consider adding a callback that is called after all features have been discovered, so the developer can programmatically register generic actions / effects / reducers.

gingters commented 1 year ago

Please also consider registering Fluxor without any automatic scanning for types at all.

I would really like to explicitly list all state types as well as explicitly list the classes that provide reducer methods as well as effects.

That way we could provide different effect implementations based on the host type (Blazor Server, Blazor WASM, Hybrid...), but still provide all implementations in the same library.

Also, maybe we have a feature in a shared library that should be registered in certain apps, but not in the current one. Configuring Fluxor discovery to explicitly omit these is a bit counter-intuitive for the normal way ASP.NET Core DI works, and also error-prone because you need to touch all other projects using your library that should not have a feature enabled to remove it from discovery. I really only want to add a feature to a project when I need it.

I'd love to have an API for that like this:

services.AddFluxor()
   .AddState<MyFeatureStateType>()
   .AddReducers<MyFirstReducerType>()
   .AddReducers<MySecondReducerType>()
   .AddEffects<MyBlazorWasmEffectType>()
gingters commented 1 year ago

@mrpmorris Would you be willing - in general - to accept a PR for an API like that to register states, reducer types, even individual reducer methods and effect types as well as individual effect methods individually without the need for auto-discovery?

mrpmorris commented 1 year ago

You should just be able to use this https://github.com/mrpmorris/Fluxor/blob/master/Source/Lib/Fluxor/DependencyInjection/FluxorOptions.cs#L34

Does that do what you need?