Following the hexagonal architecture and package design you will have somewhere an entry point reaching to your core functionality. Often this is done by using a facade.
To hide the core logic from outside i usually pass DTOs into that facades. For example imagine an File Import module which has the following facade method
public importFiles(FileImportDTO $fileimport) : FileImportResponseDTO
The FileImportDTO
belongs straight to the fileImport module because it is obviously a part of it.
Lets imagine another module in my application called User
with an UserFacade
with the following facade method
public getUserData(UserDTO $user) : UserResponseDTO
Also this case is clear since the DTO obviously belongs to that module.
But what if i have to mix both? Lets imagine i want to get the imported files for a user. How to implement this in a proper way? The nearest solution to me would be
a) extend the ImportFacade
public function getImportsForUser(UserDTO $user) : UserResponseDTO
First i would extend the UserDTO having an field for its uploads. In this solution i am a bit unhappy about having a foreign Model (UserDTO) passing to the imports. That would mean: No File import module without the user module and vice versa.
b) extend the UserFacade
public function getImportsForUser(UserDTO $user) : UserResponseDTO
Here i would also expand the UserResponseDTO
with an extra field called imports
... anyway. Also this solution seems to introduce dependencies and it feels also wrong to ask something about imports in a user facade ...
So, what is to most clean solution to this? I feel comfortable with neither of those.
Is it a good idea to pass a DTO from a foreign module to another module and declare it just as "its okay to have this dependency now" or should a translation from on model to another always be done by the business model for example?
Best regards