I'm building an application based on DDD and Hexagonal Architecture. Hexagonal architecture suggests that you shouldn't, let's say, pollute your domain with logic of elsewhere, your Domain layer should be "pure" and only containing your business logic.
But what if I have a valueobject where I want to generate an ID from an external library? UUID for example.
This is not contaminating my domain, but still, I'm importing a third party in my Domain layer and it's supposed to be placed in the Infrastructure layer.
However, do this every time I want to do this kind of things for time formats, converters... it can become kinda tedious.
Are there exceptions on third party imports in the Domain layer? If so, on what depends?
What you guys think?
Many thanks
DDD states that what is business matter goes in the domain layer, what is not does not. If the ID generation is a business logic, then there is no problem in importing that library in your domain layer. It is actually part of your domain layer, although you are not maintaining that part yourself.
When we say the domain layer should remain "pure", it means that your business logic should not be contaminated with infrastructure or presentation concerns. If the ID generation is only for persistence concerns (surrogate key), then this is an infrastructure concern, and this generation should either be done by the persistence store, or the infrastructure adapter.