ASP.NET的三層結構開發模式

來源:互聯網
上載者:User

  ASP.NET已經出來了有好幾年了,但是在開發模式上還是使用著傳統的Form模式,沒有成熟的MVC架構的支援。這種模式的缺點是很明顯的,代碼可重用性低,可擴性差,日後的修改和維護麻煩。

         為了開發的需要,我設計了一個MVC模式,大家一起交流、探討,設計得不好的地方還請各位不吝指出。

         MVC的模式結構如:

           

 

Code
using System;

using System.Text;

using System.Data;



namespace AccessHelper

{

public interface IHelper

{

DataTable ExecuteReader(string connectionString, CommandType cmdType, string cmdText);

int ExecuteNoneQuery(string connectionString, CommandType cmdType, string cmdText);

object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText);

void AddParameter(string key, object value);

}

}

 

       DbHelper模組IHelper介面的定義如下:

       IHelper用於直接執行SQL語句,它的三個主要的方法是根據Command對象的三個方法來劃分的。其中ExecuteReader方法返回的是DataTable類型,使用DataAdapter把資料Fill到DataTable中。這樣做的好處是儘早斷開資料庫的串連,釋放資源。

         DbDAO模組根據具體的Model類來定義,它的作用是把從DbHelper得來的DataTable轉換成具體的類。DbDAO通過參數DataBaseType參數,使用DBHelperFactory工廠類執行個體化相應的IHelper類。

         DbDAL模組用於處理各種的資料訪問邏輯,如登入,註冊等等。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.