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 3391310
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:47:23+00:00 2026-05-18T03:47:23+00:00

I’ve been working with DDD for a few months now and I’ve come across

  • 0

I’ve been working with DDD for a few months now and I’ve come across a few things I’m unsure of.

Take the simplistic example of adding a Product to an Order object. From our Controller, we’d have an int passed via the UI which represents a Product in the database. Which of the following two examples is correct (let me know if they’re both wrong)?

Example One:

public class OrderController
{ 
    // Injected Repositories
    private readonly IProductRepository _productRepository; 

    // Called by UI
    public void AddProduct(int productId)
    {
        Order order = ...; // Persisted Order
        Product product = _productRepository.GetProduct(productId);
        order.AddProduct(product);
    }
}

The Controller instantiates the Product itself and adds it in via the method:

void AddProduct(Product product)
{
    productList.Add(product);
}

Example Two:

public class OrderController
{ 
    // Injected Repositories
    private readonly IProductRepository _productRepository; 

    // Called by UI
    public void AddProduct(int productId)
    {
        Order order = ...; // Persisted Order
        order.AddProduct(productId, _productRepository);
    }
}

The Order domain model has the injected product repository passed to it and it gets the Product and adds it:

Product AddProduct(int productId, IProductRepository productRepository)
{
    Product product = productRepository.GetProduct(productId);
    productList.Add(product);

    return product;
}

I’ve currently gone for the first example, because your Domain Model should never call a service method internally, however I’ve seen a few examples lately that use my second example and it does look tidy. It seems to me that Example One is verging on Anaemic. Example Two would move all the Product addition logic into the Domain Model itself.

  • 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-18T03:47:24+00:00Added an answer on May 18, 2026 at 3:47 am

    Second one is horrible…

    Adding a product to order should not have the repository on its signature since repository is not part of the domain.

    I tend to go with the first one.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.