Use of BAL in 3 tier architecture?How to call methods from DAL to BAL

Normally I do the following:

  1. Define a Business Layer (BL, you call it BAL). This contains the definitions of you business entities. It also defines interfaces to retrieve/save/delete data for whatever patterns you use (repository, context, etc).
  2. Define a Data Access Layer (DAL). This contains the actual implementation for the retrieve/save/delete interfaces.
  3. Define a UI layer. This contains UI elements (forms, controls, models, controllers, etc), which can use the BL to load data.

The references are the following:

  1. The BL doesn't know the DAL or the UI.
  2. The DAL knows the BL. The DAL does not know the UI.
  3. THe UI knows the BL. The UI does not know the DAL.

The big question for you probably is, how does the BL retrieve/save/delete data when it doesn't know the DAL, and therefore cannot create an instance of a class in the DAL. Well, this is where a little Dependency Injection comes in handy. All you have to wire up is the injection of the DAL-class to the BL-interface.

Hope this makes sense. I use it as my standard 3-tier implementation, and it works absolutely without problems. Specifically, I use Entity Framework with POCO for entities, and the DI I use is a custom one, but any of the ones out there will do.

UPDATE

The BL does not know the DAL.

  • The BL defines an interface (lets call it IRepository) which it can use to do what it needs to do.
  • The DAL defines a class (Repository) which implements the interface IRepository. So the actual implementation of the repository is in the DAL.
  • Obviously the BL cannot create an instance of the repository directly. This is where dependency injection comes in, this allows the developer to create an instance of a class where it normally cannot be done. A simple crude version of this, is to use reflection.

I hope this makes more sense.