DEV Community

Building .NET 8 APIs with Zero-Setup CQRS and Vertical Slice Architecture

Artur Kedzior on January 08, 2024

The goal of this article is to introduce you to developer friendly way of building Web APIs and Azure Functions with .NET 8 applying CQRS and Verti...
Collapse
 
chrisrlewis profile image
Chris Lewis • Edited

Thanks for sharing.
We routinely use Mediatr, can you expand on what the differences are with AstroCQRS specifically for Azure Functions?
Do you have the equivalent of Mediatr cross-cutting pipeline behaviours?

Collapse
 
kedzior_io profile image
Artur Kedzior

They are very similar but AstroCQRS goes little further abstracting as much as possible in order to make it zero setup and shift developer's focus on business requirements. I read often that developers don't use Mediator because of the overhead with setting it up.

For example in AstroCQRS there is no need to inject IMediator nor explicitly call Send, you just map Minimal API endpoint to the handler and that's all. Same with Azure Functions, you map them directly to a handler. API and Azure Functions become single liners and so the code of each lives in a single handler (input, handler, response), easily findable and easily unit testable. No need to deal with spinning API's nor Functions and dealing with all that comes with it (JWT tokens, setting up headers etc.). Each handler by default allows an easy access to DbContext, RequestContext (claims, headers, languages etc) and logging. Each handler also injects and runs validators by default.

All in all it provides a developer with most of the things necessary to develop Web API or Azure Functions.

AstroCQRS also focuses on providing the best performance possible.

Unfortunately there are no pipeline behaviours supported yet. I would love to find a good use case for needing one though. Most examples I have seen is for validation (which is already builtin AstroCQRS) and global logging which I would never do myself.

I would be happy to add it though if requested here github.com/kedzior-io/astro-cqrs

Collapse
 
jangelodev profile image
João Angelo

Artur Kedzior, great post !
Thanks for sharing