当构建N层应用程序,我应该如何安排我的名字空间? [英] When Building an N-Tier application, how should I organize my names spaces?

查看:87
本文介绍了当构建N层应用程序,我应该如何安排我的名字空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,当我开始尝试在N层架构建立我的网站,我很担心性能。

So when I started trying to build my websites in an n-tier architecture, I was worried about performance.

一个谁回答问题的人告诉我,如果你申请你想最终甚至有更好的表现了良好的架构。这是涉及到编制的dll之类的东西,但现在我不知道如何命名我的命名空间。

One of the guys who answered the question told me if you applied a good architecture you'd end up with even a better performance. It's related to compiling the dlls and stuff, but now I'm not sure how to name my namespaces.

就像我有我的数据访问层的主要命名空间让我们说我有这个命名空间作为我的数据层..DAL

Like I have the main Namespace for my data access layer so let's say I have this namespace as my data layer ..DAL

但现在我有比这需要由这一层提供服务的应用实体多,每个实体都有自己的小实体。

but now I have more than entity in the application that needs to be served by this layer, and each entity has it's own smaller entities.

所以我应该包括所有的数据code下的一个命名空间(DAL),或者我应该每个实体有它自己的命名空间像DAL.E1和DAL.E2或每条干线或子实体应该有自己的空间就像DAL .E1.c1,DAL.E2,DAL.E3.c1,DAL.E3.c2 ..最后一个问题应该DAL本身包含任何类或不是?

so should I include all the data code under one Namespace (DAL) or should I each entity have it's own namespace like DAL.E1 and DAL.E2 or each main or child entity should have it's own namespace like DAL.E1.c1, DAL.E2, DAL.E3.c1, DAL.E3.c2 .. last question should DAL itself include any classes or not ?

推荐答案

这的确是一个主观的问题,每一个组织都会有完全不同的,或非常相似的模式。有没有一个最佳答案,但也有好有坏的办法。在同行业中常见的模式是基于您库名称关闭功能。例如,在我们的产品中,我们有:

This is really a subjective question, and every organization will have a completely different, or very similar pattern. There's not a best answer, but there are good and bad approaches. A common pattern in the industry is to base your library names off of features. For example, in one of our products we have:


  • 产品名称

  • ProductName.Activati​​on

  • ProductName.Activati​​on.Service

  • ProductName.Core

  • ProductName.Data
  • ProductName.Data.Customers

  • ProductName.Data.Engine

  • ProductName.Instrumentation

  • ProductName.Security

  • ProductName.ShellUI

  • ProductName.ShellUI.Windows

  • ProductName.Win32

一般遵循的模式类似,.NET Framework是一个很好的办法,或通过功能是另一回事。也许有人会说,你会不会想给你的组件,可能会暴露你的应用程序的易损部件或提请注意有意义的名字,但你永远不会被阻止海盗海盗。

Generally following a pattern similar to the .NET Framework is a good approach, or by feature is another. Some may argue that you would not want to give your assemblies meaningful names that may expose vulnerable parts of your application or draw attention, but you will never stop pirates from being pirates.

其他preFER给他们的组件非常短的名字,这仍然是即使在今天由微软完成。 (mscorlib.dll中为例)。

Others prefer to give their assemblies very short names, which is still done even today by Microsoft. (mscorlib.dll for example).

我想这一切都取决于该项目,这是怎么回事。我并不总是遵守拇指的同样的规则,但99%的时间我遵循一个共同的模式,以前的公司我工作有自己的一套模式和做法,以及

I suppose it all depends on the project and what's going on. I don't always abide to the same rule of thumb, but 99% of the time I follow a common pattern, and the former company I worked for had their set patterns and practices as well.

你的项目里面至于逻辑组织,好,祝你好运。大多数其他开发商我已经说过了说我做同样的事情。 我只是选择了一个结构/名称和它去。当然不能盲目,但也有一些想法进去,但它很难有一个最好的办法,只是指导方针。

As far as logical organization inside your projects, well, good luck. Most other developers I've talked to say the same thing I do. 'I just picked a structure/name and went with it'. Of course not blindly, but with some thought into it, but its hard to have a best approach, only guidelines.

我的建议是按功能来组织它,因为它使项目容易的管理。你知道模块1处理系统的第一部分和模块2处理第二部分,等等。一个例子是ProductName.Data.dll。在我的项目,它处理所有的数据绑定操作,如设置,preferences和数据库的交互,而ProductName.Data.Engine是允许ProductName.Data与数据层很容易沟通的框架。 (在这种情况下ProductName.Engine是实体框架的东西与其他自定义类和必要的框架部分)。

My suggestion is to organize it by feature, because it makes management of the project easy. You know that Module1 handles Part1 of the system and Module2 handles Part2, and so on. An example would be ProductName.Data.dll. In my project, it handles all data-bound operations such as Settings, Preferences, and Database interaction, while ProductName.Data.Engine is the framework that allows ProductName.Data to communicate easily with the data tier. (In this case ProductName.Engine is the Entity Framework stuff with other custom classes and required framework parts).

我想拇指另一条规则我去的是,如果模块1有很多部分组成第一部分的应用程序,我会保持这一切在模块1。除非像ProductName.Data.Engine该特性是如此之大,这是适合自己的图书馆,以便于管理。

I guess another rule of thumb I go by is if Module1 has many parts that make up Part1 of the application, I would keep it all in Module1. Unless like in ProductName.Data.Engine where that feature was so large, it was suited to its own library for easier management.

所有的一切,好运气,因为组织结构为项目变大,但如果你把一切都整洁,有组织,有很好发现,然后了解你的项目将是易于管理不断的斗争。

All in all, good luck, because organization and structure is constant struggle as projects become large, but if you keep everything tidy, organized, and well found and understood then your project will be easy to manage.

这篇关于当构建N层应用程序,我应该如何安排我的名字空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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