Where to put the helper class in the DDD architecture?

I have already read the answers to this similar question , but I believe my needs are different.

I have a class in my domain layer, one of its methods has to read from a file in order to get a certain value, so I thought about creating a helper class to read the file and keep it as clean and minimal as possible. A

getValue

getValue

Since this is my first time using DDD, and based on the modest knowledge I have, I think that the helper class can be placed in the domain layer as it will be used.

Does the helper class put a smart choice in the domain layer? if not, is there a better DDD compatible solution?

+3


source to share


2 answers


I do not recommend touching the filesystem within the domain / aggregates as they need to be clean. If, however, you are using CQRS + Event sourcing, you can do the IO on the read side, but be careful with replay, as the application state must be rebuilt at any time.



If you are not using CQRS but some kind of tiered architecture and you have to do IO, then you have to invert the dependencies to the infrastructure (where the IO is done). To do this, you can define an interface within the domain level and an implementation at the infrastructure level.

+3


source


Reading data from a file should be carried out at the infrastructure level, as well as work with a database, external services, interact with a low-level API, etc. This is technical code, not domain logic. He should be there.

In DDD, you can use services to host some supporting code, unless it's domain logic and not a factory, of course. You can also use a repository object that creates an interface within the domain and an implementation at the infrastructure level.



Thus, you can create the IMyDataRepository interface at the domain level and the MyDataRepository class in the frameworks defining the infrastructure level at the application level.

+4


source







All Articles