domain driven design - DDD referencing large data sets / injecting repository? -
i struggling find best solution following. need determine whether country "inuse", (e.g. referenced address).
i have next simplified model mapped in nhibernate:
class address { public country country {get; set;} } class country { public list<address> addresses {get; set;} bool isinuse() { homecoming addresses.any(); } }
using isinuse method on country inefficient, result in load of countries (the .any() executed in memory). in addition, country doesn't need know addresses, it's purely there isinuse method. so, above illustration consumer point of view, feels domain object should expose isinuse method, not perform , contains unnecessary relationships.
other options can think of are;
just utilize repository , phone call straight service layer. repository encapsulate phone call issued select count(*), rather select *, case lazy load alternative above. options leave isinuse logic exclusively outside of domain layer. inject repository isinuse(), calls out same above. have read bad ddd practise.does have advice or improve solutions problem.
hope above makes sense... thanks.
i suggest not calculate each time perform query. denormalize isinuse
. each time address added or removed country can determine whether country in utilize , save value.
how go determining value story , there various techniques ranging determining when save address , updating country's isinuse
value or using messaging if these happen entities in different bcs.
domain-driven-design repository-pattern
No comments:
Post a Comment