Pergunta

While learning domain driven design, I have been putting together the following solution (note that this ordering is lexicographic and not a representation of dependency):

enter image description here

Below is an outline of each project:

Domain.Models: Domain entities and value objects (e.g. Order)

Domain.Interfaces: Domain service interfaces and repository interfaces (e.g. IOrderService, IOrderRepository)

Domain.Services: Concrete implementations of domain services interfaces (e.g. OrderService)

Infrastructure.Data: Concrete implementations of repository interfaces (e.g. OrderRepository)

Infrastructure.DependencyResolution: Dependency injection resolution.

Problem

Now I would like to provide non-domain services. An example would be an email gateway for the sending of emails. I have created the following project for this:

Infrastructure.Components: Concrete implementations of non-domain services

Question

Where would I put the interfaces for such non-domain services (for example, an IEmailGateway)?

It would need to be accessible by the Domain.Services project (an OrderService might need you send out a notification), so would it go in Domain.Interfaces? I would say NO since sending an email is not a domain-specific activity.

Foi útil?

Solução

I would say NO since sending an email is not a domain-specific activity.

Sure, but you could get away by using a higher domain abstraction. The Domain doesn't care about emails but Notifications would be a perfect domain concept. It actually already seems to be part of the Ubiquitous Language, since you used that term in your question. So something along the lines of INotifier instead of IEmailGateway.

Alternate approaches could be :

  • Have the overarching Application Service send the email via an IEmailService interface defined in the Infrastructure.

  • Have the Order entity or domain service raise a Domain Event. An EmailService in the Infrastructure layer listens to it and sends the email.

Outras dicas

If sending an email is not a concept of your bounded context then it means it's a part of another one. So you should apply some of the bounded contexts integration patterns such as anticorruption layer of domain events.

Whatever you choose I see another issue with your structure and solving that will eliminate the problem in the question. Try to structure your application in terms of bounded contexts and modules that use Ubiquitous Language rather then types of objects. So rather than Interfaces, Models and Services you should have Products, Clients, Shipments etc..

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top