读petshop3.0--多层应用架构(z)

来源:互联网 发布:网络管理软件下载 编辑:程序博客网 时间:2024/05/17 10:03
petshop是C#实现的petstore,具体和技术无关的情况就不多介绍了。
petshop3.0比petshop1和2都有了较大的改变,主要是设计方面的。看一下里面的8个工程和1个站点就知道它肯定分了不少层。
一.概况介绍。
Model:
模型层,封装业务实体,一般和数据库模式对应。
例如:
       public class AccountInfo {
 
              // Internal member variables
              private string _userId;
              private string _password;
              private string _email;
              private AddressInfo _address;
              private string _language;
              private string _category;
              private bool _showFavorites;
              private bool _showBanners;
              。。。
       }
IDAL:
数据访问接口层,主要是一些dao接口。
例如:
       public interface IAccount
       {
              AccountInfo SignIn(string userId, string password);
              AddressInfo GetAddress(string userId);
              void Insert(AccountInfo account);
              void Update(AccountInfo Account);
       }
 
OracleDAL:
oracle实现的数据访问层。
 
SQLServerDAL:
sql实现的数据访问层。
OracleDAL和SQLServerDAL中的类都实现了IDAL中的接口。属于dao实现。
 
DALFactory
负责确定是使用oracle实现还是mssql实现。通过在web.config中的配置确定使用哪一个dal实现(通过反射,动态生成访问类是PetShop.SQLServerDAL还是PetShop.OracleDAL命名空间中的类)。
              <add key="WebDAL" value="PetShop.SQLServerDAL"/>
              <add key="OrdersDAL" value="PetShop.SQLServerDAL"/>
       public class Account
       {
              public static PetShop.IDAL.IAccount Create()
              {                  
                     /// Look up the DAL implementation we should be using
                     string path = System.Configuration.ConfigurationSettings.AppSettings["WebDAL"];
                     string className = path + ".Account";
 
                     // Using the evidence given in the config file load the appropriate assembly and class
                     return (PetShop.IDAL.IAccount) Assembly.Load(path).CreateInstance(className);
              }
       }
 
BLL:
业务访问层。通过DALFactory,读取配置,决定使用何种dal实现。
       public class Account {         
              public AccountInfo SignIn(string userId, string password) {
 
 
                     if ((userId.Trim() == string.Empty) || (password.Trim() == string.Empty))
                            return null;
 
                     // 通过DALFactory调用具体的dal实现。
                     IAccount dal = PetShop.DALFactory.Account.Create();
 
                     // Try to sign in with the given credentials
                     AccountInfo account = dal.SignIn(userId, password);
 
                     // Return the account
                     return account;
              }
              。。。
}
 
Web:
表现层,主要包括了Web 页面(aspx)和用户控件(ascx)控件及自定义服务器控件SimplePager和ViewStatePager。
 
Utility:
公用模块,一组帮助器类,其他业务层和数据访问层可能会使用到的一些公用方法。
原创粉丝点击