建议对于一个新手关于N层应用 [英] Advice For A Newbie About N-Tier Applications

查看:143
本文介绍了建议对于一个新手关于N层应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了人,这里有另外一个你们大家:

Okay people, here's another one for ya'll:

我开始在N层应用程序的世界。我已经做了专题一些阅读和一般的建议是,N层应用程序的目标是抽象的功能吐温层。所以,在此基础上,在一个n层应用程序的常规模式是:

I'm starting in the n-tier apps world. I've done some reading on the topic and general advice is that n-tier apps' objective is to abstract functionality tween layers. So, based on this, in a n-tiered app the regular model is:

数据访问 - >业务层 - >演示

由于我是一个.NET开发人员,我认为,加强与多种客户端(Silverlight的,网络应用,甚至一个WinForms客户端)我整合应在业务层使用WCF(Windows通信基础)作为数据服务,以便客户端可以将其考虑其类型的通信。此外,我NHibernate的一个巨大的风扇作为一个ORM。所以,我的结构是这样的:

Since I'm a .NET developer, I thought that to enhance integration with multiple client types (Silverlight, Web app or even a WinForms client) I should use WCF (Windows Communication Foundation) as data services at the business layer so clients can communicate to it regardless of its type. Also, I'm a huge fan of NHibernate as a ORM. So my structure goes like this:

数据访问(NHibernate的) - >业务层(WCF) - >演示(WPF,ASP.NET,的WinForms

好了,那就是安装程序。我在这种方式共新手,所以我想我可以在这里发表请求建议在此设置。另外,我对如何设置这个在VS的解决方案,我喜欢在不同的项目不同的层很迷茫,但对于数据对象的抽象(如客户,订单等)?难道我把时间在一个单独的库?又是怎么回事WCF?我只知道一个程序员的罪过的数据类通过电缆传输到客户机。什么是专业的方式来实现这一目标?

Okay, so that is the setup. I'm a total newbie in this kind of approach, so I thought I could post here requesting for advice on this setup. Also, I'm very confused on how to setup this in a VS solution, I like to separate layers in different projects, but what about abstraction of data objects (like Customer, Order, etc.)? Do I put em in a separate library? And what about WCF? I know is a programmer's sin to transfer the data classes over the wire to the client. What's the professional's way to achieve this?

谢谢,任何意见将非常感激。

Thanks, any advice would be very appreciated.

推荐答案

这是相当多的目标。N层是位比不过N层比较复杂,可以通过询问来对比,你的图层实际上住在单独的物理服务器?

That's pretty much on target. N-Tier is a bit more complex than N-Layer however, and can be contrasted by asking, "Are your layers actually living on separate physical servers?"

根据多么复杂,您的业务层上是,你可能要抽象的进一步商业和服务层之间。通常,这两个都非常紧密地联系在一起,住在同一个物理服务器上。服务层往往充当门面您BLL。

Depending on how complex your Business layer is, you might want to abstract it further between a Business and Service layer. Typically those two are tied very closely and live on the same physical server. The service layer often acts as a Facade to your BLL.

如果你是表示层是在同一台服务器上,比你的ASP.NET或WinForms的应用程序可能要,与BLL通信,而无需通过WCF服务会

If you're Presentation layer is on the same server, than your ASP.NET or WinForms apps might want to communicate with the BLL without going through WCF services.

阅读上微软模式与放大器;实践 - 应用架构指南

您的域对象应该活在自己的组件通常你的域模型。据微软框架设计准则,这是很好的做法,因此将项目命名为集会:

Your Domain objects should live in their own assembly typically your domain model. According to Microsoft Framework Design Guidelines, it's good practice to name your project assemblies accordingly:

[公司] [ProductOrComponent] [...]

[Company].[ProductOrComponent].[...]

我碰巧喜欢的名字间距的这种格式,一般使用。:

I happen to like this format of name-spacing and generally use:

[公司]。[产品]。[层] [子]。[...]

[Company].[Product].[Layer].[SubLayer].[...]

下面是一个使用的解决方案文件夹来组织各个项目的例子解决方案:

Here is an example solution using solution folders to organize each project:

在这个例子中,我有一个BLL层和服务层。服务层提供了一个WCF库中的实际实施,同时演示实际上包含WCF Web应用程序托管服务。它总是分头从接口实现很好的做法。

In this example, I have a BLL and Service layer. The Service layer provides the actual implementation in a WCF Library while the Presentation actually contains the WCF Web application to host the services. It's always good practice to split up implementation from interface.

/客户端文件夹可以忽略不计,我只是用它作为测试样本控制台应用程序。消耗你的服务的客户端应用程序也许应该有自己的解决方案,否则你将要管理一个庞大的解决方案。

The /Client folder can be ignored, I just use that as a sample console app for testing. Any Client applications that consume your service should probably have their own solution or you're going to be managing a huge solution.

至于你的数据对象被转移过线...我假设你从你的ORM指的是类。 (域模型)你是正确的它通常被认为是不好的做法。该溶液是用数据传输对象。您可以从图片中看到我有一个.Dto库。如果你能使用工具,如AutoMapper,比我为这一切,然而,增加DTO对您的解决方案与它进一步的复杂性和维护带来的。我相信恐龙埃斯波西托写了关于这个问题的好文章。将尽力帮您找到它。

As for your data object being transferred over the wire... I'm assuming you mean the classes from your ORM. (Domain Model) You're correct its generally considered bad practice. The solution is using Data-Transfer Objects. You can see from the picture I have a .Dto library. If you're able to use tools like AutoMapper, than I'm all for it, however, adding DTO's to your solution brings with it further complexity and maintenance. I believe Dino Esposito wrote a good article on the subject. Will try to find it for you.

希望这有助于。

我要指出,我不熟悉NHibernate的能力。有可能是使用ORM更好的解决方案。我只与实体框架的工作。

I should note, I'm unfamiliar with nHibernate's capabilities. There might be better solutions for using that ORM. I've only worked with Entity Framework.

查看迪诺·埃斯波西托的 - 的优点和数据传输对象的缺点

Check out Dino Esposito's - The Pros and Cons of Data Transfer Objects

这篇关于建议对于一个新手关于N层应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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