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. Currently, too many assemblies must be referenced by an end-consumer due to inheritance issues. For example, he开发者_如何学Cre is my basic project setup:
MyProject.Domain
namespace MyProject.Domain
{
public interface IFooable{}
public class Foo : IFooable{}
}
MyProject.Contracts
namespace MyProject.Contracts
{
[DataContract]
public class FooData : IFooable{}
[ServiceContract]
public class IFooService
{
IEnumerable<FooData> GetFoos();
}
}
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.
Is there a way around this?
Its pretty straightforward- define IFooable in Contracts, not in Domain.
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.
精彩评论