存储库模式:需要多少个存储库才能获取具有两个地址的联系人?
如果您有一个联系人,与地址具有 1:* 关系,并且可能还有一个或多个其他表用于保存持久值对象 - 应该有多少个存储库?
是否应该只有一个 ContactRepository 具有一个公共方法(GetContact(),该方法在内部调用一个私有方法 (GetAddresses)),该方法返回一个完全水合的实体(Contact+Addresses)?
或者应该有两个存储库——一个用于联系人,一个用于地址,并且 COtactsRepository 调用 AddressRepository?
还是其他?
谢谢你!
If you have one Contact, with a 1:* relationship with Addresses, and possibly one or more other tables used to hold the persisted value objects -- how many repositories should there be?
Should there be just one ContactRepository with one public method (GetContact(), that internally calls a private method (GetAddresses)) that returns a fully hydrated entity (Contact+Addreses)?
Or should there be two Repositories -- one For Contacts, one for Addresses with the COntactsRepository calling the AddressRepository?
Or other?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了联系人之外,其他任何东西都可以有地址吗?
如果没有,我可能会考虑只拥有一个 ContactRepository。
如果还存在具有地址的实体(例如订单、事件等),我会考虑一个单独的 AddressRepository。
您的 Mulberry 道路/车道示例意味着您只需要“123 Mulberry Rd”的一个地址记录,无论有多少联系人拥有该地址,这很可能会产生更多动力来创建 AddressRepository。
Can anything other than a Contact have an Address?
If not, I'd probably think about having just a ContactRepository.
If there also exist entities like Orders, Events, etc, that have Addresses, I'd think about a separate AddressRepository.
Your Mulberry road/drive example implies that you only want one address record for "123 Mulberry Rd", no matter how many Contacts have that address, that might well create more impetus to do an AddressRepository.