0
Answer

DAL desing using DAAB 4.0

Ask a question
simon A

simon A

15y
3.7k
1
Hi, I'm working on a .Net 3.5 web application.It has various modules say for example Customers,Orders,etc.... I need to a design Data Access Layer (DAL) for the same using Enterprise Library 4.0 (using Data Access Application block or DAAB) to connect to SQL Server 2008. Here is how i plan to go about it: 1.Have an interface called "IDataService".It will have members like "ExecuteReader()","ExecuteScalar()","ExecuteNonQuery()", "AddParams",etc...basically, this interface will almost look like that of DAAB. 2.Have a class called "DataService" which implements this interface.This class will act as a wrapper over DAAB and each of the method will use the corresponding method in DAAB internally. 3.Have Business classes(or Data Containers) like Customer,Data, etc which will have properties mapping to their corresponding tables attributes in the database. 4.Have DAL classes for each module like CustomerDataService, OrdersDataService, etc.Each of these classes will have constructor code in which I will instantiate DataService class as below: IDataService dataService= new DataService() Also, each of these classes will have methods like: GetCustomerDetails() AddCustomer() RemoveCustomer() UpdateOrder etc. These methods will internally use "dataService" object to make any operation on the database ExecuteReader,ExecuteNonQuery, etc 5.Have a mapper class for each module like "CustomerMapper","OrderMapper",etc. These class will take datasource(for example IDataReader) as input and would fill in the data in the generic collection (List,List). And these mapper classes will be internally called by the corresponding Dataservice class to return the type-safe collection to the calling client. 6.Have a helper class like DbHelper which will do tasks like "handling DBNull cases","storing stored procedure names",etc. 7.DataService classes will be inturn used by the BusinessLogic layer classes...ie CustomerBusiness,OrdersBusiness,etc. 8.Business Logic layer will return the collection to the presentation layer . Does this design make any sense?What are the advantages/disadvantages of this approach? The advantage I could think of this approach is all DataService classes will alway program against the interface "IDataService" without needing to know how "DataService" class is implemented internally.So tomorrow,if i remove DAAB and use another API inside my DataService class, the client code need not change. Also,I can add any method in my IDataService interface which is not present in DAAB....for example BatchUpdate().... Please correct me if i am wrong. Thanks in advance! Cheers, Simon