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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:05:19+00:00 2026-06-08T10:05:19+00:00

In my mind it feels like we need an inversion of construction here. The

  • 0

In my mind it feels like we need an inversion of construction here.

The entity is relying upon services to populate various properties, within itself. This should be palmed off to a builder, shouldn’t it? (That is the construction of the object) I’m looking at legacy code and performing some general refactoring.

In essence the entity should be pretty dumb, there seems to be mix of processing going on it that Im pretty certain should/could be broken out.

  • 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-06-08T10:05:20+00:00Added an answer on June 8, 2026 at 10:05 am

    Injecting services into domain entities might not be a good idea, but maybe not for the reason you think.

    In essence the entity should be pretty dumb, there seems to be mix of
    processing going on it that Im pretty certain should/could be broken
    out.

    It’s a controversial matter, but many believe that dumb domain entities is an anti-pattern (Anemic Domain Model) and goes against the object oriented style of programming. Entities should not just contain data but also encapsulate behavior.

    The problem is, how much behavior can you add before your domain object starts suffering low cohesion ? In your example, relying upon services to populate various properties is a typical borderline case between what is the domain object’s responsibility (cohesive) and what isn’t. In addition, if the properties are explicitely loaded from a database, this might be a violation of the persistence ignorance principle.

    If it turns out that these properties need to be initialized right from the birth of the object, I agree with you that a Factory or a Builder could be a better place to fetch that data and assemble the entity, especially if the construction logic is complex.

    But usually, such a mechanism is there to provide lazy loading, in other words to populate the properties on-demand and just in time. This allows to defer costly operations such as fetching potentially big data from a database and avoids having a big object graph loaded in memory right from the start.

    While I personally wouldn’t be offended to see Services injected in entities at construction time for lazy loading purposes, some consider it bad practice : see here and here. You might prefer to use method injection or delegate injection for cleaner, more testable entities.

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

Sidebar

Related Questions

I'd like to know what's the default approach for those times when you need
I have a need to implement a rating feature and would like to do
I feel like I have lost my mind because I am sure I have
I feel really silly asking this, but it is completely blowing my mind why
Well! I feel really stupid for this question, and I wholly don't mind if
I have in mind a simple alarm app for the purpose of hourly alerts/reminders.
I broken my mind understanding mapreduce. So, I ask you for help. I have
(Keep in mind this is on OSX Snow Leopard) I don't know how to
I'm losing my mind on this one. My last question answered a syntax issue,
This is boggling my mind today. I have a bash script to set a

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.