C# – Communication between BLL and DAL

bllcdata-access-layernetvb.net

Solution setup:

  • DAL (class library)
  • BLL (class library)
  • Common (class library (some common functionality – enums, logging, exceptions,…))
  • Application1 (Windows Application)
  • Application2 (Windows Application)
  • WebApp (Web application)

Let's say I have a Customer entity, which is:

  • a table in SQL server
  • a CustomerDataTable in DAL
  • a Customer class in BLL
  • a BLL.Customer class in all the applications

What kind of objects should BLL and DAL use for communication – DataTable or List<Customer> (for example)? In first case, BLL logic should transform Customer object to DataTable and send it to DAL. In secod case, DAL layer should be aware of Customer class, which is in BLL layer. But originaly DLL references DAL and not opposite…

Should I put all classes into seperate assembly, which is referenced by all others (Common, BusinessObjects, …)? In this case I could use Customer class in all my projects.

Should I even bother to seperate DAL and BLL when I know, that only one BLL will use my DAL. In this case I could merge them together into one project.

PS – I am reading about DataTables and a lot of people say that we shouldn't use them at all. What are better options? Maybe it is time for me to learn some ORM mapping tools 🙂

Best Answer

In my opinion you should have another Layer (seperate dll). Like "domain", where would you keep all entities like Customer. Then simply include in all higher levels(DAL, BLL, UI and others) in hierarchy this assembly.

Sample architecture can look like this:

(Database) <-> DAL <-> BL <-> UI

and on all levels you will have access to "domain" layer. DAL should return List not a DataTable. On some stage your development process you may want to use in DAL some OMR like NHibernate with would also return a List, probably.