Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6538739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:46:19+00:00 2026-05-25T10:46:19+00:00

Despite having studied Domain Driven Design for a long time now there are still

  • 0

Despite having studied Domain Driven Design for a long time now there are still some basics that I simply figure out.

It seems that every time I try to design a rich domain layer, I still need a lot of Domain Services or a thick Application Layer, and I end up with a bunch of near-anemic domain entities with no real logic in them, apart from “GetTotalAmount” and the like. The key issue is that entities aren’t aware of external stuff, and it’s bad practice to inject anything into entities.

Let me give some examples:

1. A user signs up for a service. The user is persisted in the database, a file is generated and saved (needed for the user account), and a confirmation email is sent.

The example with the confirmation email has been discussed heavily in other threads, but with no real conclusion. Some suggest putting the logic in an application service that gets an EmailService and FileService injected from the infrastructure layer. But then I would have business logic outside of the domain, right? Others suggest creating a domain service that gets the infrastructure services injected – but in that case I would need to have the interfaces of the infrastructure services inside the domain layer (IEmailService and IFileService) which doesn’t look too good either (because the domain layer cannot reference the infrastructure layer). And others suggest implementing Udi Dahan’s Domain Events and then having the EmailService and FileService subscribe to those events. But that seems like a very loose implementation – and what happens if the services fail? Please let me know what you think is the right solution here.

2. A song is purchased from a digital music store. The shopping cart is emptied. The purchase is persisted. The payment service is called. An email confirmation is sent.

Ok, this might be related to the first example. The question here is, who is responsible for orchestrating this transaction? Of course I could put everything in the MVC controller with injected services. But if I want real DDD all business logic should be in the domain. But which entity should have the “Purchase” method? Song.Purchase()? Order.Purchase()? OrderProcessor.Purchase() (domain service)? ShoppingCartService.Purchase() (application service?)

This is a case where I think it’s very hard to use real business logic inside the domain entities. If it’s not good practice to inject anything into the entities, how can they ever do other stuff than checking its own (and its aggregate’s) state?

I hope these examples are clear enough to show the issues I’m dealing with.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:46:20+00:00Added an answer on May 25, 2026 at 10:46 am

    A user signs up for a service. The user is persisted in the
    database, a file is generated and saved (needed for the user account),
    and a confirmation email is sent.

    You can apply Dependency Inversion Principle here. Define a domain interface like this:

    void ICanSendConfirmationEmail(EmailAddress address, ...)
    

    or

    void ICanNotifyUserOfSuccessfulRegistration(EmailAddress address, ...)
    

    Interface can be used by other domain classes. Implement this interface in infrastructure layer, using real SMTP classes. Inject this implementation on application startup. This way you stated business intent in domain code and your domain logic does not have direct reference to SMTP infrastructure. The key here is the name of the interface, it should be based on Ubiquitous Language.

    A song is purchased from a digital music store. The shopping cart
    is emptied. The purchase is persisted. The payment service is called.
    An email confirmation is sent. Ok, this might be related to the first example. The question here is, who is responsible for orchestrating this transaction?

    Use OOP best practices to assign responsibilities (GRASP and SOLID). Unit testing and refactoring will give you a design feedback. Orchestration itself can be part of thin Application Layer. From DDD Layered Architecture:

    Application Layer: Defines the jobs the software is supposed to do and directs the
    expressive domain objects to work out problems. The tasks this layer
    is responsible for are meaningful to the business or necessary for
    interaction with the application layers of other systems.

    This layer is kept thin. It does not contain business rules or
    knowledge, but only coordinates tasks and delegates work to
    collaborations of domain objects in the next layer down. It does not
    have state reflecting the business situation, but it can have state
    that reflects the progress of a task for the user or the program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unfortunately, despite having tried to learn regex at least one time a year for
Despite having very little Linux experience, I'm too enticed by VPS (and too sick
Despite primarily being a windows user, I am a huge fan of rsync. Now,
I have to work on several VB6 legacy projects and despite some good VB6
I'm asking this question despite having read similar but not exactly what I want
I've got the DTD for OFX 1.03 (their latest version despite having developed and
I wrote a setter and getter method following Apple's conventions and noticed that despite
I know there are several similar questions on SO, I have used some of
Having realised my own reasons were way too dubious, I've now gone about this
I'm still trying to figure out how the revision numbering works with bzr, despite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.