[Spring.NET筆記] DataAccess with DI

摘要:[Spring.NET筆記] DataAccess with DI

網路上已有很多Spring的介紹,就不多說

如標題,這是筆記 XD 所以,只是能執行,完全沒有符合架構設計

Web.config

 

這邊要注意的一點是,設定<resource uri="assembly://Core/Core.Config/setting.xml" />時

需將setting.xml透過屬性視窗,將【建置動作】設定為 內嵌資源

 

setting.xml


EmployeeDao.cs

 

public DataTable GetEmp()
{
    string SQL = "select * from Employees";
 
    return this.AdoTemplate.ClassicAdoTemplate.DataTableCreate(CommandType.Text, SQL);
}

EmployeeDao裡的AdoTemplate是透過DI的方式初始化
而AdoTemplate是繼承了 Spring.Data.Generic.AdoDaoSupport

 

Default.aspx.cs

 

//透過DI,取得設定檔中的EmployeeDao的設定
IApplicationContext appContext = ContextRegistry.GetContext();
EmployeeDao emp = (EmployeeDao)appContext["EmployeeDao"];

DataTable tb = emp.GetEmp();