WCF 和工厂设计模式 [英] WCF and factory design pattern

查看:41
本文介绍了WCF 和工厂设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用某种工厂"设计模式创建了一个非常复杂的应用程序.这样,我有定义一个类的接口,我有一个实现接口的类,我有一个带有静态方法的静态类,用于创建一个实例.那个静态方法(工厂方法)返回接口类型,只有工厂类可以访问我的类型类.所以,如果我有私有类 A,我将有公共接口 IA 和静态工厂类 Factory.Factory"类是唯一可以访问A"的类,它返回类型IA".这样,整个项目都在使用接口(例如IA"),将接口作为参数传递等等.简而言之,除了工厂类之外,我的应用程序从不使用A"类.

I have created a pretty complicated app using some sort of "factory" design pattern. That way, i have interface defining a class, i have a class implementing the interface and i have a static class with static method for creating an instance. That static method (factory method) returns interface type, and only factory class can access my type class. So, if i have private class A, i'll have public interface IA and static factory class Factory. "Factory" class is the only one that can access "A", and it returns type "IA". That way, entire project is working using interfaces (for example "IA"), passing interfaces as arguments and so long. Simply put, my app is NEVER using class "A" except in factory class.

现在,棘手的部分 - 我决定将我的应用程序拆分为客户端和服务器部分.那些部件将使用 WCF 进行通信.但是我有一个问题 - 使用 WCF 我不能像我在 WHOLE CODE SO FAR 中那样使用接口作为返回类型/参数.

Now, the tricky part - i have decided to split my app to client and server part. Those to parts will communicate using WCF. But i have a problem - with WCF i can't use interfaces as return types / arguments like i did in WHOLE CODE SO FAR.

请问有没有任何方法可以让我的项目在不改变我的只知道接口"代码的基础的情况下工作?

Please is there ANY way to make my project work without changing the very base of my "know-only-interface" code?

推荐答案

创建一个与接口 IA 具有相同属性的类.您可以将服务操作的返回类型指定为此类的类型.在服务操作中,创建此类的对象(DTO)并映射来自 IA 类型的对象的值.现在你可以返回这个 DTO.

Create a class with the same properties as in the interface IA. You can specify the return type of the service operation to be the type of this class. In the service operation, create an object (DTO) of this class and map the values from the object of type IA. Now you can just return this DTO.

这篇关于WCF 和工厂设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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