与WCF服务共享域模型 [英] Sharing domain model with WCF service

查看:102
本文介绍了与WCF服务共享域模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是很好的做法,参考我的Web应用程序领域层类库WCF服务应用程序。

Is it good practice to reference my web applications domain layer class library to WCF service application.

这样做,让我轻松访问我的域模型已经存在的类,这样我就不用再重新定义相似的类要使用WCF服务

Doing that gives me easy access to the already existing classes on my domain model so that I will not need to re-define similar classes to be used by the WCF service

在另一方面,我不喜欢它创建的应用程序和服务之间的耦合,我很好奇,如果它能够从长远来看创建我的困难。

On the other hand, I don't like the coupling that it creates between the application and service and i am curious if it could create difficulties for me on the long run.

我也觉得有专用类我的WCF的应用程序会更有效,因为这些类仅包含将要使用的服务,并没有其他的成员。如果我使用的类从我的域层会有将不被使用的服务的类许多领域,这将导致不必要的数据传输。

I also think having dedicated classes for my WCF app would be more efficient since those classes will only contain the members that will be used by the service and nothing else. If I use the classes from my domain layer there will be many fields in the classes that will not be used by the service and it will cause unnecessary data transfer.

我会AP preciate,如果你能给我你的想法从你的经验

I will appreciate if you can give me your thoughts from your experience

推荐答案

我个人不赞成直接传递域对象直接通过WCF。由于克日什托夫说,它是关于一个数据合同不是的,你是越过线的东西的行为的合同。

I personally frown on directly passing domain objects directly through WCF. As Krzysztof said, it's about a data contract not a contract about the behavior of the the thing you are passing over the wire.

我通常做到这一点:

  • 定义数据契约在自己组装
  • 在服务引用了两个数据契约组件和业务实体组件。
  • 在服务命名空间
  • 创建扩展方法的实体映射到其对应的数据契约,反之亦然。
  • Define the data contracts in their own assembly
  • The service has a reference to both the data contracts assembly and the business entity assemblies.
  • Create extension methods in the service namespace that map the entities to their corresponding data contracts and vice versa.

把一个什么样的数据契约是不谈,如果你开始传递的实体在你身边的共享实体建立由WCF边界每侧拉不同的设计方向的概念纯度。不可避免地,你将最终获得只属于一方,或者更糟糕的行为 - 有公开的方法,在概念上做同样的事情,但以不同的方式为WCF边界两侧。它可能会变得非常凌乱长期。

Putting the conceptual purity of what a "Data Contract" is aside, If you begin to pass entities around you are setting up your shared entity to pulled in different design directions by each side of the WCF boundary. Inevitably you'll end up with behaviors that only belong to one side, or even worse - have to expose methods that conceptually do the same thing but in a different way for each side of the WCF boundary. It can potentially get very messy over the long term.

这篇关于与WCF服务共享域模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆