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

  • Home
  • SEARCH
  • 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 6469797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:02:08+00:00 2026-05-25T06:02:08+00:00

I’ve asked a previous question last month, about whether an Entity should access a

  • 0

I’ve asked a previous question last month, about whether an Entity should access a Repository, and although it looks like most people think they shouldn’t, I have to admit it’s hard for me to get convinced.

I have a use case for which I really can’t think of any (reasonable) way to do the logic without injecting the Repository in my Entity:

We have a Store, which is assigned a Zone (city, district, … – user defined).
To reduce the workload of the employee in charge of adding Stores to the database, and to ensure consistency, we don’t ask him to select the Zone in which he wants to add the Store. He just zooms on a map, clicks to pinpoint the Store location, and saves. The application then has to find the most relevant Zone for this location.

What I currently have is something like:

class Store
{
    protected Zone zone;
    protected Point location;
    protected ZoneRepository zoneRepository;

    public void setLocation(Point location)
    {
        Zone matchingZone = this.zoneRepository.findByLocation(location);
        if (matchingZone == null) {
            throw new ApplicationException(
                "The store location must be within a zone boundary");
        }
        this.location = location;
        this.zone = matchingZone;
    }
}

Do you have any solid alternative which would support the commonly accepted opinion that this design is inherently bad?

  • 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-25T06:02:09+00:00Added an answer on May 25, 2026 at 6:02 am

    From the description you’ve provided it seems that Point is actually not part of your Ubiquitous Language – the Zone is. You don’t set a point for store – you assign a Zone to it. In other words, the signature of this operation shouldn’t be setLocation(Point location) – it should be assignZone(Zone locationZone). The translation between point selected by user and the zone should occur before domain model operation is performed. That’s how I’d model it.

    Example added after comments (C# if you don’t mind – and shows only a concept). Code assumes command-based approach to performing user actions – that’s how I tend to do it, but might be an Application Service or Controller even, depending on the structure of your application.

        public class StoreLocationHandler : Handles<LocateStoreCommand>
        {
            public void Handle(LocationStoreCommand command)
            {
                // Location contains coordinates as well as zone info and can be obtained only via LocationService
                Location location = LocationService.IdentifyZone(command.Coordinates); 
    
                Store store = StoreRepository.Get(command.StoreId);
    
                store.AssignLocation(location);
    
                // persist changes - either by Unit of Work or Repository
            }
        }
    

    The point is that you don’t have to craete everything inside your domain entities – Zone seems to be Value Object from perspective of Store. Besides, further separation of those two concepts might lead to additional possibilities, like identifying the zone not online but through some kind of background process (for the sake of performance or scalability). In addition, in my opinion it fits better considering Dependency Injection principle.

    After all, domain doesn’t care about how the zone is created or retrieved, it cares about association between Store, its location and the zone it falls into. Why should it be responsible for translation between a point and a zone? At least that’s the way I see it.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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.