We are designing an application with clean/hexagonal architecture paradigm but we are newbies on this. So we have some questions.
The scenario is:
- We have an external SOAP service who gives to us some "Entity" information and related "Document"
- For every Entity the application must:
- store all the Entity Documents on a CMS (content and some Entity-attributes)
- store Entity on DDBB with stored Document reference
Lets see our initial solution on java-like approach:
Entity and Document
class Entity {
private String id;
// other attributes ...
private Document xml;
private Document pdf;
// some business logic
}
class Document {
private long id;
//other attributes
InputStream getStream() {...}
}
FRepositori abstraction at Domain Layer
class EntityRepositori {
Entity create(Entity entity);
...
}
DocumentRepositori abstraction at Domain Layer
class DocumentRepositori {
Document create(Document document)
...
}
ExternalService abstraction at Application Layer for the SOAP service
class ExternalService {
List<Entity> getEntities();
...
}
An Use Case implementation at Application Layer
class IncorporateEntityUseCase {
IncorporateFUserCase(EntityRepositori, DocumentRepositori, ExternalService){...}
void incorporate() {
List<Entity> entities = externalService.getEntities();
for (Entity entity : entities) {
Document xml = dRepository.create(entity.getXmnl());
Document pdf = dRepository.create(entity.getPdf());
entity.setXml(xml);
entity.setPdf(pdf);
entityRepository.create(entity);
}
}
}
Questions
- About ExternalService, it is correct to define its abstraction with Entity and Document or must it returns some ValueObject that UseCase implementations will transform to entities?
- About Document, must we design it as an aggregate root and eliminate Document object references from Entity?