3层架构 - 在需要的例子 [英] 3 Tier Architecture - In need of an example

查看:109
本文介绍了3层架构 - 在需要的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

presently我使用单层结构的工作。现在我想学习如何编写使用3层架构code。请你能给我提供一个简单的例子?

Presently I am working using single tier architecture. Now I am wanting to learn how to write code using 3 tier architecture. Please can you provide me with a simple example?

推荐答案

这是我在我的项目。不仅仅是一个传统的三层架构。

This is what I have in my project. More than just a traditional 3-tier architecture.

1) Application.Infrastructure


  • 所有的BusinessObjects基类,业务内容对象集合,数据访问类和我的自定义属性和公用事业扩展方法,通用验证框架。这就决定了我最后的.NET应用程序的整体行为的组织。

2)的 Application.DataModel


  • 类型化数据集的数据库。

  • TableAdapter的扩展合并交易及其他功能我可能需要。

3。) Application.DataAccess


  • 数据访问类。

  • 实际地方的数据库操作使用查询基本类型化数据集。

4。) Application.DomainObjects


  • 业务对象和业务对象的集合。

  • 枚举。

5)的 Application.BusinessLayer


  • 提供从presentation层访问管理器类。

  • HttpHandlers的。

  • 自己的网页基类。

  • 更事情在这里..

6。) Application.WebClient Application.WindowsClient


  • 我的presentation层
  • 从Application.BusinessLayer和Application.BusinessObjects注意到引用。

Application.BusinessObjects跨应用程序使用,他们只要跨neeeded [除Application.DataModel和Application.Infrastructure]

Application.BusinessObjects are used across the application and they travel across all layers whenever neeeded [except Application.DataModel and Application.Infrastructure]

我所有的查询只定义Application.DataModel。

All my queries are defined only Application.DataModel.

Application.DataAccess返回或需要的业务对象的任何数据存取操作的一部分。业务对象与反射属性的帮助下产生。每个业务对象标有一个属性映射到目标表中的数据库和业务对象内的属性标记具有属性映射到目标在各个数据基表coloumn

Application.DataAccess returns or takes Business objects as part of any data-access operation. Business objects are created with the help of reflection attributes. Each business object is marked with an attribute mapping to target table in database and properties within the business object are marked with attributes mapping to target coloumn in respective data-base table.

我的验证框架,让我验证每个字段指定ValidationAttribute的帮助。

My validation framework lets me validate each field with the help of designated ValidationAttribute.

我framrwork大量使用属性来最繁琐的任务,像自动映射和验证。我也可以将新的功能作为框架新的方面。

My framrwork heavily uses Attributes to automate most of the tedious tasks like mapping and validation. I can also new feature as new aspect in the framework.

一个示例业务对象看起来像这样在我的应用程序。

A sample business object would look like this in my application.

User.cs

[TableMapping("Users")]
public class User : EntityBase
{
    #region Constructor(s)
    public AppUser()
    {
        BookCollection = new BookCollection();
    }
    #endregion

    #region Properties

    #region Default Properties - Direct Field Mapping using DataFieldMappingAttribute

    private System.Int32 _UserId;

    private System.String _FirstName;
    private System.String _LastName;
    private System.String _UserName;
    private System.Boolean _IsActive;

    [DataFieldMapping("UserID")]
    [DataObjectFieldAttribute(true, true, false)]
    [NotNullOrEmpty(Message = "UserID From Users Table Is Required.")]
    public override int Id
    {
        get
        {
            return _UserId;
        }
        set
        {
            _UserId = value;
        }
    }

    [DataFieldMapping("UserName")]
    [Searchable]
    [NotNullOrEmpty(Message = "Username Is Required.")]
    public string UserName
    {
        get
        {
            return _UserName;
        }
        set
        {
            _UserName = value;
        }
    }

    [DataFieldMapping("FirstName")]
    [Searchable]
    public string FirstName
    {
        get
        {
            return _FirstName;
        }
        set
        {
            _FirstName = value;
        }
    }

    [DataFieldMapping("LastName")]
    [Searchable]
    public string LastName
    {
        get
        {
            return _LastName;
        }
        set
        {
            _LastName = value;
        }
    }

    [DataFieldMapping("IsActive")]
    public bool IsActive
    {
        get
        {
            return _IsActive;
        }
        set
        {
            _IsActive = value;
        }
    }

    #region One-To-Many Mappings
    public BookCollection Books { get; set; }

    #endregion

    #region Derived Properties
    public string FullName { get { return this.FirstName + " " + this.LastName; } }

    #endregion

    #endregion

    public override bool Validate()
    {
        bool baseValid = base.Validate();
        bool localValid = Books.Validate();
        return baseValid && localValid;
    }
}

BookCollection.cs

/// <summary>
/// The BookCollection class is designed to work with lists of instances of Book.
/// </summary>
public class BookCollection : EntityCollectionBase<Book>
{
    /// <summary>
    /// Initializes a new instance of the BookCollection class.
    /// </summary>
    public BookCollection()
    {
    }

    /// <summary>
    /// Initializes a new instance of the BookCollection class.
    /// </summary>
    public BookCollection (IList<Book> initialList)
        : base(initialList)
    {
    }
}

这篇关于3层架构 - 在需要的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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