onebeyond / monaco

Template for .NET projects
MIT License
42 stars 10 forks source link

FEATURE: Single file commands/queries #57

Closed CesarD closed 9 months ago

CesarD commented 10 months ago

Detailed Description

To convert the current structure that Monaco currently has about Commands/Validators and Queries folders to one where each Command and Query are placed in the same file with their corresponding handlers. This is oriented to decompress the bloating that sometimes might affect the Commands/Queries Handlers files when there are too many commmands/queries for an entity.

Context

In order to better group together queries with their handlers and commands with their respective validators and handlers, it could be better to group each of them together in a single file, to further simplify the navigation between a query and its handler, the same as with a command with its respective validator and handler. This should make it simpler to navigate through the structure, would align to the vertical slicing more properly, simplify handlers files that sometimes get too bloated when there are too many commands/queries, and would also simplify the testing, aligning it, as well, to the vertical slicing concept as all the tests related to a same slice would be easier to group themselves instead of having a big handlers test class that will contain all tests for all the handlers of a same entity as we currently have. A con to this approach is that some of the shared code between some slices won't be contained in the same handlers class, within reach of all the different handlers (same would occur with the tests); but I think the solution for this can be as easy to create more extensions and static classes/methods in an "Extensions" folder to contain all the shared code there.

Possible Implementation

To use it as an example, the current folder from Application.Features.Company could be structured like this:

Each of the features (Create/Edit/Delete Company and Get Page/ById) would be separated into different files with a class that will nest 3/2 other classes (depending on whether it's a command or query), and each of these nested classes would be the specific command/query, its handler and (in the case of the commands) its validator.