摘要:[Enterprise Library 5 筆記] DataAccess with DI
網路上已有很多 Enterprise Library 的介紹,就不多說
如標題,這是筆記 XD 所以,只是能執行,完全沒有符合架構設計
Web.config
web.config可透過EntLibConfig.exe來編輯
設定上跟原本web.config的設定沒什麼不同
DI的處理,是透過Unity (<unity configSource="Setting.config" />)
Setting.config
Default.aspx.cs
public IEmployeeDao EmployeeDao { get; set; } //public IEmployeeService EmployeeService { get; set; } protected void Page_Load(object sender, EventArgs e) { //EmployeeDao = new EmployeeDao(); IUnityContainer container = new UnityContainer().LoadConfiguration("DI"); this.EmployeeDao = container.Resolve<EmployeeDao>(); //EmployeeService = Core.Utility.ServiceHelper.GetServiceInstance<IEmployeeService>(); var result = from p in this.EmployeeDao.GetAllData() where p.TitleOfCourtesy == "Ms." select new { 都市 = p.City, 電話 = p.HomePhone }; //var result = this.EmployeeService.GetEmployeeAllData().Where(p => p.TitleOfCourtesy == "Ms.").Select(p => new { 都市 = p.City, 電話 = p.HomePhone }); this.gvData.DataSource = result; this.gvData.DataBind(); }