您的设计应该是可维护的。这就是我的项目中的内容。
1.) Application.Infrastructure
- 所有业务对象的基类、业务对象集合、数据访问类以及我的自定义属性和实用程序作为扩展方法,通用验证框架。这决定了我最终的 .net 应用程序的整体行为组织。
2.) Application.DataModel
- 数据库的类型化数据集。
- TableAdapters 已扩展以包含我可能需要的事务和其他功能。
3.) Application.DataAccess
- 数据访问类。
- 使用底层类型化数据集查询数据库操作的实际位置。
4.) Application.DomainObjects
5.) Application.BusinessLayer
- 提供可从表示层访问的管理器类。
- HttpHandlers。
- 我自己的 Page 基类。
- 这里有更多内容..
6.) Application.WebClient 或 Application.WindowsClient
- 我的表示层
- 从 Application.BusinessLayer 和 Application.BusinessObjects 获取引用。
Application.BusinessObjects 在整个应用程序中使用,并在需要时跨越所有层 [Application.DataModel 和 Application.Infrastructure 除外]
我所有的查询都只定义了 Application.DataModel。
Application.DataAccess 作为任何数据访问操作的一部分返回或获取业务对象。业务对象是在反射属性的帮助下创建的。每个业务对象都标有到数据库中目标表的属性映射,业务对象中的属性标有与相应数据库表中目标列的属性映射。
我的验证框架允许我在指定的 ValidationAttribute 的帮助下验证每个字段。
我的框架大量使用属性来自动化大多数繁琐的任务,例如映射和验证。我还可以将新功能作为框架中的新方面。
示例业务对象在我的应用程序中如下所示。
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)
{
}
}