I’m doing an task based application using Vertical Slice Architecture (VSA) and domain driven design (DDD). Tasks split into commands and queries and using Mediator pattern.
Say I’m having an Order domain object but multiple commands, which do some work and based on that, has to create one or more orders in the system. That could be commands for multiple integrations to retrieve the orders (e-mail, FTP etc.). What is the best options to share some validation logic before allowing each of these to create these orders (verify not already exists in database given some unique keys, verify some limits etc.)?
One option could be to create a specific CreateOrder command to contain that logic, but it seems like an anti-pattern to call commands from commands.
Right now I have created and injected an OrderFactory-class to each of these commands (similar to a service) which returns the domain object (uncommitted), but that does not feel like the right solution.