wcf最佳设计原则 [英] wcf best design principles

查看:90
本文介绍了wcf最佳设计原则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望对现有的WCF服务进行一些更改。我想知道是否最好使超级方法(例如Save())使用接收到的值来决定要采取的操作,或者是否应该将这些操作分解为自己的方法并将其公开给消费者决定何时打电话给他们。

I am looking to make some changes to an existing WCF service. I wanted to know if it would be best to make super methods such as a Save() that would use the values received to decide what action to take or if I should break the actions out into their own methods and expose those for the consumer to decide when to call them.

例如,我有一个付款处理程序,可以在商家进行付款尝试及其结果时接收来自我们商家的通知。对我来说,允许处理程序以状态更改传递对象并让super方法尝试弄清楚该怎么做(假设没有错误将数据弄乱了)还是创建一个单独的方法来扩展会更好呢?

For instance, I have a payment handler that receives notifications from our merchant when they make a payment attempt and its results. Would it be better for me to allow the handler to pass in the object with a status change and let the super method attempt to figure out what to do with it (assuming no bugs have messed the data up) or create a separate method to extend so the intention is clearly defined.

请注意,超级方法还负责保存数据和更改过程中其他步骤的状态。

Note that the super method is also responsible for saving data and changing status along other steps in the process.

我在Google周围搜索,但实际上并没有发现任何具体内容。在我看来,超级方法违反了SOLID,但是我被告知WCF有一套不同的标准,并且最好制定超级方法,因此消费者不必思考。

I have googled around but haven't really found anything specific. To me the super method violates SOLID but I was told WCF has a different set of standards and its best to make super methods so the consumers don't have to think.

欢迎任何反馈:)

推荐答案

我发现最好将服务操作存在于具有业务意义的级别上。

I find that it's best if service operations can exist at a level where they have business meaning.

这是什么意思,如果一个业务人员被告知操作名称,他们将大致了解调用该操作将执行的操作,并可以猜测该数据是什么将需要传递给它。

What this means is that if a business person was told the operation name, they would understand roughly what calling that operation would do, and could make a guess at what data it would require to be passed to it.

要做到这一点,您的运营应全部或部分完成某些业务流程。

For this to happen your operations should fulfill in full or in part some business process.

例如,以下操作签名具有业务含义:

For example, the following operation signatures have business meaning:

void SolicitQuote(int brokerId, int userId, DateTime quoteRequiredBy);

int BindPolicyDocument(byte[] document, SomeType documentMetadata);

Guid BeginOnboardEmployee(string employeeName, DateTime employeeDateOfBirth);

如果您在考虑服务组合时使用此主体,那么好处是您很少会偏离最佳路径;您知道每个操作的作用,并且知道何时不再需要该操作。

If you use this principal when thinking about service composition then the benefit is that you will rarely stray far from the optimal path; you know what each operation does and you know when an operation is no longer needed.

另一个好处是,由于业务流程很少发生变化,因此您无需进行太多更改服务合同。

An additional benefit is that because business processes change fairly rarely you will not need to change your service contracts as much.

这篇关于wcf最佳设计原则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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