Opinions on using Mediatr with SS?

I’ve always implemented the CQS library Mediatr, in all my aspnet mvc and SS solutions, mainly because I like to keep the Services/Controllers thin.

But recently in the SS projects I’m wondering if it’s overkill to always delegate the code to mediatr when it can be so easily coded into the service.

Do you have an opinion on this?

No opinion, as I’ve never used it.

To expand as a general rule I value simplicity above all else and prefer the minimum LOC and abstractions required which effectively ends up following YAGNI. So I’ll need a reason and realize some tangible benefit for adding indirection and moving code outside a Service, the most likely reason being code reuse of a partial implementation (given a Service is like any other logic class with injectable dependencies).

The approach for code reuse is generally to prefer extension methods which adds the least overhead whilst letting you create self-descriptive code. But if the reusable implementation requires access to multiple dependencies I’ll push the code down to a shared dependency instead (e.g. a Data Access layer).

But if I need to reuse the entire Service implementation I’ll just call the Service through the gateway so there’s no need to move parts of the implementation elsewhere.

That is a fantastic reply, the Gateway is something I missed! thank you.

SS is a fantastic framework but it is an uphill battle to unlearn all the frameworks/libraries/techniques picked up over the years and to do it within SS, and sometimes you don’t realise a feature/functionality is available in SS!.

1 Like