wemogy / libs-cqrs

CQRS framework
http://libs-cqrs.docs.wemogy.com/
MIT License
0 stars 0 forks source link

Introduce `IQueryPreProcessor` support #51

Closed SebastianKuesters closed 1 year ago

SebastianKuesters commented 1 year ago

As a developer I want to have the option to define a IQueryPreProcessor for my query. This could be useful in the following sample:

Given is the following query:

public class GetSharedLinkPermissionsQuery : IQuery<GetSharedLinkPermissionsQueryResult>
  {
      public Guid? SharedLinkId { get; set; }

      public SharedLink? SharedLink { get; set; }

      public GetSharedLinkPermissionsQuery(Guid sharedLinkId)
      {
          SharedLinkId = sharedLinkId;
      }

      public GetSharedLinkPermissionsQuery(SharedLink sharedLink)
      {
          SharedLink = sharedLink;
      }
  }

For this I would like to add a PreProcessor, which requests the SharedLink entity from the database, if the constructor with the Guid parameter was used. Using this I can ensure, that in the IQueryHandler implementation both properties are always set, so that I can focus on the Core logic.

SebastianKuesters commented 1 year ago

@robinmanuelthiel pls give me feedback on this feature request.

robinmanuelthiel commented 1 year ago

I don’t like this idea at all, as see a bunch of anti-patterns here.

First of all, IMHO a query should always only work exactly one way. In this case by passing the SharedLink object in the constructor. In cases where I only have the Guid at hand, I should use a different query (e.g. GetSharedLinkQuery) first and then pass the result into this query.

This would make calls a lot simpler and especially clearer in terms of easier to read and to follow.

Not a big fan of magic pre-processors which are hidden to the caller anyways

SebastianKuesters commented 1 year ago

Like the approach of forcing two queries here, which prevents code duplication if a GetSharedLinkQuery is needed one day.

robinmanuelthiel commented 1 year ago

We should come up with written down rules and best-practises on how we write and sctructure Queries (and Commands) across our projects!

robinmanuelthiel commented 1 year ago

Documented https://github.com/wemogy/libs-cqrs/pull/52