业务对象是否应该知道其相应的合约对象
我有一些业务对象和一些非常相似的相应数据契约对象,用于通过 WCF 服务通过网络获取数据。
我应该使用什么机制从业务对象获取填充的数据协定对象?
在理想的情况下,数据契约层应该了解业务层吗?
或者
业务层应该了解数据契约层吗?
或者
是否应该有另一个具有静态方法(如 GetDataContractFromBusinessObject)的映射层?
I have some business objects and some very similar corresponding data contract objects for getting data across the wire via WCF service.
What mechanism should I use to get populated data contract objects from business objects?
In an ideal world, should the data contract layer know about the business layer?
or
Should the business layer know about the data contract layer?
or
Should there be another mapping layer that has static methods like GetDataContractFromBusinessObject?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我非常喜欢你提到的“使用静态方法的映射层”技术。这样,您的业务对象和数据契约就不会相互依赖。
I am a big fan of the "mapping layer with static methods" technique you mention. Then, your business objects and data contracts don't depend on each other either way.
我经常会添加一个派生类来处理来自业务层中特定后备存储的数据消耗。
另一种选择是业务类可以理解的接口数据层表示。然后让您的数据层实现该接口。我更喜欢这种方法,因为让业务层与数据层的抽象版本交互然后让数据层理解您的业务对象要简单得多。
I often will add a derived class to handle data consumption from a specific backing store in my business layer.
Another option is to an interface data layer representation that the business class understands. And then have your data layer implement that interface. I prefer this method as it is much simpler to have you business layer interact with an abstracted version of your data layer then having your data layer understand your business objects.