简体   繁体   English

WCF N层架构

[英]WCF N-Tier Architecture

I'm working on a fairly straight forward multi-tier application (WPF, WCF, EF 4, and SQL). 我正在开发一个相当简单的多层应用程序(WPF,WCF,EF 4和SQL)。 As far as architecture is concerned, we were planning to include a single "Common" project which will include both entities as well as service contracts. 就架构而言,我们计划包括一个“共同”项目,其中将包括实体和服务合同。

Are there any advantages/disadvantages to having entities and service contracts in separate assemblies? 将实体和服务合同放在单独的程序集中是否有优点/缺点? Or is it usually good to keep them together? 还是将它们放在一起通常是件好事?

I'm interested in hearing the opinion of others. 我有兴趣听取别人的意见。

Thanks! 谢谢!

Having Contracts in a separate assembly gives you the advantage of the ability injecting to a different entities in a different assembly by providing the Contracts assembly to a developer , and he would implement it and give you a dll that you can put inside the project folder and inject to it using IoC framework like StructureMap without rebuilding, 通过将合同提供给开发人员,可以将合同放在单独的程序集中,从而为您提供了在不同程序集中注入不同实体的能力,他将实现合同,并为您提供一个dll,您可以将其放入项目文件夹中,使用IoC框架(如StructureMap)注入它,而无需重建,

having the contracts in the same assembly that contains the entities tie the contracts to the implementations... 让合同在包含实体的同一程序集中,将合同与实现联系起来...

If you are using a RESTful architecture with other .NET platform consumers - it's helpful to have the Service Contracts in a separate assembly (Shared) so that you can easily share your operation and data contracts with RESTful consumers without exposing any unnecessary data access components to your clients. 如果您将RESTful体系结构与其他.NET平台使用者一起使用-将服务合同放在单独的程序集中(共享)会很有帮助,这样您就可以轻松地与RESTful使用者共享您的操作和数据合同,而不会暴露任何不必要的数据访问组件您的客户。

I would recommend that you keep the data access and service contracts isolated for this reason. 因此,我建议您将数据访问和服务合同保持隔离状态。

That is exactly how I structured the design for an e-commerce n-tier app I designed. 这正是我为设计的电子商务n层应用程序设计结构的方式。

There are two common libraries - one for DTO's and another for interfaces. 有两个常见的库-一个用于DTO,另一个用于接口。

Then the client and server included those librarues, and the service proxies were generated using common types. 然后,客户端和服务器包括这些库,并且使用通用类型生成服务代理。

The main advantage here is ease of compilation - you don't have to recreate the proxies when you change the insterface, the client and server are updated automatically. 这里的主要优点是易于编译-更改界面时不必重新创建代理,客户端和服务器会自动更新。

I also had a utilities app that contained all the helper type stuff I needed. 我还有一个实用程序应用程序,其中包含我需要的所有帮助程序类型的东西。

EDIT: Sorry, just re-read your question. 编辑:对不起,请重新阅读您的问题。 In my case, I had multiple interface libraries - one for the workflow library (with composed interfaces), and another for services (the thing being composed into workflow operations) 就我而言,我有多个接口库-一个用于工作流库(具有组合的接口),另一个用于服务(将其组成工作流操作)

So in my case it made sense to keep them seperate. 因此,就我而言,将它们分开是有意义的。

If you only have one set of interfaces, and those interfaces all make use of your DTO's, there is no reason to seperate them into two libraries - one would be sufficient. 如果您只有一组接口,并且这些接口都使用了DTO,则没有理由将它们分成两个库-一个就足够了。 Consider though if you may need to share your DTO's between more interface libraries in future, in that case rather keep the DTO's seperate from the interfaces from the start. 考虑一下,如果将来可能需要在更多接口库之间共享DTO,那么在这种情况下,请从一开始就将DTO与接口分开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM