Pergunta

Speaking about DDD, in which layer should a hypothetical MailerInterface be?

I know the implementation (or adapters) for each specific mail sender package should be in the infrastructure, but these implementations will implement an Interface.

This interface should be inside the domain or application layer?

Foi útil?

Solução

Speaking about DDD, in which layer should a hypothetical MailerInterface be?

You'll want to review the Dependency Inversion Principle, and the Onion Architecture / Hexagonal Architecture.

An easy guess it that you define the interface in the same layer as the consumer (it is, after all, a part of the consumer's contract). Following this idea, the interface would be defined in the application layer (since that's where the interaction with other processes/systems should happen), and the implementation would be in the infrastructure layer.

An alternative approach is to separate the abstractions completely from the details - so the definition of the contract (meaning, the abstractions of the producer and the consumer) would be an isolated thing with no dependencies on the details, and the application and infrastructure layers would each implement their role of the contract.

You wouldn't normally include the definition of the interface in the domain layer, because fetching information from other systems is an application concern, not a domain concern (the general purpose theme of our domain layer is bookkeeping; the application that hosts the domain model is responsible for the interactions with the outside world).

Licenciado em: CC-BY-SA com atribuição
scroll top