orm - DDD - Access repositories from entities, bis -


I asked last month whether an entity should use a repository, and although it seems that most people It seems that they have to admit that it is difficult for me to be confident.

I have a case of use, for which I can not really think of any ( appropriate ) method without logging the repository in my unit without injection:

We have store , which is zone (city, district, ... - user-defined). In order to reduce the workload of the employee in charge of adding the store to the database, and to ensure consistency, we do not ask it to select the area in which the store wants to add it just zooms on the map, Clicks to indicate the store location, and saves. The app then needs to find the most relevant area for this place.

What I currently have is:

  class store {protected area area; Safe location location; Protected area area zonaropository; Public zero set location (point location) {zone match zone = this.zoneRepository.findByLocation (location); If (mailing zones == blank) {new application exception ("store location should be within a territory limit"); } This.location = location; This.zone = MailingJohn; }}   

Do you have any concrete option that will support commonly accepted opinions that this design is naturally bad?

From the description provided by you, it seems that the point is actually your universal language < / Em> - the zone you do not set a point for the store - you specify a zone for it. In other words, the signature of this operation is set to setLocation (point location) Should not be - it should be assigned the zone (zone locations) . The translation between the user and the region selected points must be done before the domain model operation. In the same way I model it.

The example was added after the comment (C # if you do not talk - and only shows a concept) code looks like a command-based approach to the user's actions - how do I like it But it may be a application service or controller depending on the structure of your code. Public Square Shop Location Handler: Handles & lt; LocateStoreCommand & gt; {Public wired handle (locationstore command command) {// place coordination as well as zone information and can be specified by location service location = location service only. Identified (commandAnnet); Store Store = StoreRepository.Get (command.StoreId); Store.AssignLocation (location); // The change continues - either by the work or the unit of the repository}}

The issue is that you do not need to attract all things within your domain units - the zone Price object appears to be in addition to the store, apart from the two concepts, there may be additional possibilities, such as not identifying the area not online, but some types of background process Due to (for performance or scalability). Apart from this, in my opinion, it is thinking better on the theory.

After all, the domain does not care about how the area has been built or recovered, it is in between stores Relationship falls in its place and zone. Why should one be responsible for the translation between a point and a field? At least in this way I see it.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -