mrpmorris / Fluxor

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

Interface / Type-Safe Dispatch method? #268

Closed sinnerbenkei closed 2 years ago

sinnerbenkei commented 2 years ago

Would this functionality be easily doable or has it been ruled out in the past?

Currently we have IDispatcher.Dispatch(object), what are the chances we could get a variation method which requires some interface or base class/record, to allow for typesafety?

For example say i have: Queries.GetFirstItem as a mediatr query Actions.GetFirstItem as a Fluxor action

I can restrict sending improper messages through mediatr because they must all implement an interface, however by allowing the generic object parameter type it is very easy to send the wrong type through idispatcher

This is important because when handling effects you are restricted to the idispatcher functionality, since you cannot extend the idispatcher interface for the injected handler method

I have found two workarounds, either add an extension method, or write a custom wrapper method in each effect it is needed (or inherit)

Thank you for all your effort on this project

mrpmorris commented 2 years ago

Hi

I did once have an IAction interface, but I didn't want shared libraries to also have to reference Fluxor (e.g. a contracts project).

The extension method is the approach I would recommend.