Intermediate compute call before domain creation in DDD(Domain Driven Design)

63 Views Asked by At

I have a UI that takes visitor orders. After the visitor placing his order, UI has a button that calculates tax and gets back to the UI before placing the actual order. 

I have DDD based order API with ADD, UPDATE, GET, GET ALL and DELETE endpoints. But for the intermediate "Get Tax" button what should I do? Is it a Query(CQRS) side operation or an API Endpoint that talks to different service classes to get the result before domain creation.

1

There are 1 best solutions below

0
Andreas Hütter On

If this calculation is based on business logic but does not require any persistent data to do it's job rather than the input you should simply put this logic into a domain service. That means, if the calculation itself is also not persisted.

You can also reuse this domain service at other places than in case you need it. Even as a parameter to an aggregate root's method.

So in your case I would simply call the domain service from the controller to perform the calculation. But make sure the domain services method will receive some value object placed in the domain layer as well as a method parameter (or just a primitive if that's enough) rather than any controller related objects (like request).