[英]Avoid exposing too many assemblies to client consuming WCF service
I need a bit of guidance here. 我需要一些指导。 I have a WCF service that is part of a larger solution.
我有一个WCF服务,它是更大的解决方案的一部分。 Currently, too many assemblies must be referenced by an end-consumer due to inheritance issues.
目前,由于继承问题,最终消费者必须引用太多程序集。 For example, here is my basic project setup:
例如,这是我的基本项目设置:
MyProject.Domain MyProject.Domain
namespace MyProject.Domain
{
public interface IFooable{}
public class Foo : IFooable{}
}
MyProject.Contracts MyProject.Contracts
namespace MyProject.Contracts
{
[DataContract]
public class FooData : IFooable{}
[ServiceContract]
public class IFooService
{
IEnumerable<FooData> GetFoos();
}
}
MyProject.Proxies MyProject.Proxies
namespace MyProject.Proxies
{
public class WCFClient{}
}
The problem lies here: 问题在于:
class ConsumerCode
{
private WCFClient = new WCFClient();
void consumeService()
{
// Compiler error. No reference to MyProject.Domain.IFooable
var foos = WCFClient.GetFoos();
}
That means an end-consumer who uses the FooData object will have to also include a reference to MyProject.Domain , which stinks because I shouldn't have to expose the Business Logic Layer to the end-client of a WCF service. 这意味着使用FooData对象的最终用户还必须包含对MyProject.Domain的引用,因为我不必将业务逻辑层暴露给WCF服务的最终客户端。
Is there a way around this? 有没有解决的办法?
Its pretty straightforward- define IFooable in Contracts, not in Domain. 它非常直接 - 在合同中定义IFooable,而不是在域中。
The logic here is that anything that is exposed to the client is (by definition) a contract or part of a contract, not a domain entity. 这里的逻辑是,暴露给客户的任何东西(根据定义)是合同或合同的一部分,而不是域实体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.