简体   繁体   English

asp.net中的分层架构是什么模式?

[英]What pattern is layered architecture in asp.net?

I am a asp.net developer and don't know much about patterns and architecture.我是一名 asp.net 开发人员,对模式和架构了解不多。 I will very thankful if you can please guide me here.如果你能在这里指导我,我将非常感激。

In my web applications I use 4 layers.在我的 web 应用程序中,我使用了 4 层。

  1. Web site project (having web forms + code behind cs files, user controls + code behind cs files, master pages + code behind cs files) Web 网站项目(有 web forms + 代码隐藏 cs 文件,用户控件 + 代码隐藏 cs 文件,母版页 + 代码隐藏 cs 文件)

  2. CustomTypesLayer a class library (having custom types, enumerations, DTOs, constructors, get, set and validations) CustomTypesLayer 一个 class 库(具有自定义类型、枚举、DTO、构造函数、get、set 和验证)

  3. BusinessLogicLayer a class library (having all business logic, rules and all calls to DAL functions) BusinessLogicLayer 一个 class 库(具有所有业务逻辑、规则和对 DAL 函数的所有调用)

  4. DataAccessLayer a class library( having just classes communicating to database.) DataAccessLayer 一个 class 库(只有与数据库通信的类。)

-My user interface just calls BusinessLogicLayer. -我的用户界面只调用 BusinessLogicLayer。 BusinessLogicLayer do proecessign in it self and for data it calls DataAccessLayer functions. BusinessLogicLayer 自行处理数据,并调用 DataAccessLayer 函数处理数据。

-Web forms do not calls directly DAL. -Web forms 不直接调用 DAL。

-CustomTypesLayer is shared by all layers. -CustomTypesLayer 由所有图层共享。

Please guide me is this approach a pattern?请指导我这种方法是一种模式吗? I though it may be MVC or MVP but pages have there code behind files as well which are confusing me.我虽然它可能是 MVC 或 MVP,但页面也有文件背后的代码,这让我感到困惑。

If it is no pattern is it near to some pattern?如果没有模式,它是否接近某种模式?

That's not four layers, that's three layers, so it's a regular three tier architecture. 那不是四层,而是三层,所以它是常规的三层体系结构。

The CustomTypesLayer is not a layer at all. CustomTypesLayer根本不是一个图层。 If it was, the user interface would only use the custom types layer and never talk to the business layer directly, and the data access layer would never use the custom types layer. 如果是这样,则用户界面将仅使用自定义类型层,而从不直接与业务层对话,而数据访问层将永远不使用自定义类型层。

The three tier architecture is a Multitier architecture 三层架构是多层架构

As far as patterns go, I recommend getting to grips with these: 就模式而言,我建议您掌握以下内容:

  • My biggets favourite by a mile is the Dependency Inversion Principle (DIP), also commonly known as (or at least very similar to) Inversion of control (IoC) ans Dependencey Injection; 我最喜欢的一项是依赖反转原理 (DIP),它也通常称为(或至少非常类似于) 控制反转 (IoC)和依赖注入。 they are quite popular so you should have no problem finding out more info - getting examples. 它们非常受欢迎,因此您应该可以轻松找到更多信息-获取示例。 It's really good for abstracting out data access implementations behind interfaces. 对于在接口后面抽象出数据访问实现非常有用。
  • Lazy Load is also useful. 延迟加载也很有用。 Interestingly, sometimes you actually might want to do the opposite - get all the data you need in one big bang. 有趣的是,有时您实际上可能想做相反的事情-一次获得所需的所有数据。
  • Factory pattern is a very well known one - for good reason. 工厂模式是一个非常著名的模式-这是有充分理由的。
  • Facade pattern has also helped me keep out of trouble. 立面模式也帮助我摆脱了麻烦。

Wikipedia has a pretty good list of Software design patterns , assuming you haven't seen it yet. 假设您还没有看到Wikipedia,那么它会列出相当不错的软件设计模式

A final thing to keep in mind is that there are three basic types of patterns (plus a fourth category for multi-threaded / concurrency); 最后要牢记的是,存在三种基本类型的模式(加上多线程/并发的第四类); it can help just to know about these categories and to bear them in mind when you're doing something of that nature, they are: 它可以帮助您了解这些类别,并在进行此类操作时记住这些类别,它们是:

  • Creational 创造力的
  • Structural 结构性
  • Behavioral 行为的

Take a look at the Entity Framework or LinqToSQL. 看一看实体框架或LinqToSQL。 They can both generate your data access layer automatically from your database. 它们都可以从数据库自动生成数据访问层。 This will save you a lot of (boring) work and allow you to concentrate on the interesting layers. 这将节省您很多(无聊的)工作,并使您可以专注于有趣的图层。

Code-behind does not really have anything to do with architecture - it is more of a coding style. 后台代码实际上与体系结构没有任何关系-它更多是一种编码风格。 It is a way of separating logic from presentation. 这是一种将逻辑与表示分离的方法。 Any architecture you mention can be used with or without code-behind. 您提到的任何体系结构都可以使用或不使用代码隐藏。

You seem to be describing a standard three-tier architecture. 您似乎正在描述标准的三层体系结构。 MVC is a pattern than describes how your layers and the user interact. MVC是一种模式,用于描述您的图层和用户如何交互。 The user requests a page (represented by a View), which requests its data from the Controller. 用户请求一个页面(由View表示),该页面向Controller请求其数据。 The Controller communicates with your business layer (Model) to extract the correct data and passes it to your View for display. Controller与您的业务层(模型)进行通信以提取正确的数据,并将其传递给您的View以进行显示。 If the View is interactive, for instance it allows the user to update something, then this user action action is passed back to your Controller, which would call the relevant method against the business layer to save the update to the database. 如果视图是交互式的,例如它允许用户更新某些内容,则此用户操作操作将传递回您的控制器,后者将针对业务层调用相关方法以将更新保存到数据库。

Hope this helps. 希望这可以帮助。

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

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