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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:51:41+00:00 2026-05-27T18:51:41+00:00

Possible Duplicate: Why not use an IoC container to resolve dependencies for entities/business objects?

  • 0

Possible Duplicate:
Why not use an IoC container to resolve dependencies for entities/business objects?

I asked a very similar question in the past. However, I believe this is not a self-duplicate: the (good) answer to my original question was very specific to this domain problem, and does not discuss the problem in general.

Let’s take a new example I came accross:

  • I have a Zone entity, with an associated boundary;
  • I have a Store entity, which has a location as well as a zone property;
  • A ZoneRepository can find which Zone contains a specific location.

The zone property of the Store should never be set directly, but instead deducted from the location when this property is assigned. Therefore, it sounds logical to me to do this:

class Store
{
    public void setLocation(Point location, ZoneRepository repo)
    {
        this.location = location;
        this.zone = repo.findByLocation(location);
    }
}

Are there drawbacks, caveats to this approach? If so, can you suggest realistic alternatives?

  • 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-27T18:51:42+00:00Added an answer on May 27, 2026 at 6:51 pm

    What is the relationship between Zone and Location? Zone must have a Location property, correct? Or otherwise you wouldn’t be able to search zone by location. Could this be a bi-directional relationship? What I’m getting at, is why can’t you do this?

    class Store
    {
        public function setLocation(Point $location)
        {
            $this->location = $location;
            $this->zone = $location->zone;
        }
    }
    

    alternatively, you cold use the repository in the layer above, and then just pass in what you need:

    class Store
    {
        public function setLocation(Point $location, Zone $zone)
        {
            $this->location = $location;
            $this->zone = $zone;
        }
    }
    

    Generally, I would not inject the repository in unless absolutely necessary, and in this situation it is not. Even then, I would not pass it into the method, I would pass it in using an IOC container.

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

Sidebar

Related Questions

Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Why not use tables for layout in HTML? These days, I am
Possible Duplicate: How do I use arrays in C++? I am not sure if
Possible Duplicate: When do you use Java's @Override annotation and why? My question is
Possible Duplicate: Why not use tables for layout in HTML? When should I use
Possible Duplicate: Why not use tables for layout in HTML? Just wondering, I thought
Possible Duplicate: Why not use tables for layout in HTML? i know that using
Possible Duplicate: PHP class instantiation. To use or not to use the parenthesis? I'm
Possible Duplicate: If you're not supposed to use Regular Expressions to parse HTML, then
Possible Duplicate: When should I use a List vs a LinkedList This question is

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.