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
Zoneentity, with an associated boundary; - I have a
Storeentity, which has alocationas well as azoneproperty; - A
ZoneRepositorycan find whichZonecontains 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?