views:

232

answers:

3

I know this is a very basic question. But I am really not able to comprehend what should we have in BLL. Let me take an example.
Let us consider a Login.aspx web page, which is used to facilitate user login.
In this case Login.aspx will have two textboxes and one login button.(Presentation Layer).
Data Acess Layer will have functions to check if username and password are correct.


I dont think I need something else in this page. So what will I have in BLL. If you want to add some functionlity that should come in BLL, please add.

+4  A: 

No, the BLL checks if the username and password are correct. The DAL is only for data access.

kprobst
so you mean, on click of login button, i will call a function in BLL which checks if username and password is correct by passing them to DAL
vaibhav
@kprobst, should I write a Sql query to in BAL
vaibhav
For example, let's say that you're retrieving a password hash based on the user name, and verifying it against the provided password. The DAL is used to pull the data off the table where that is stored, the BLL is used to verify the hash.In general no logic should reside in the database, whether business or not. That goes in the business layer. This is not always possible, but you should strive to keep as much code out of the DB as possible. Consider the DAL (ORM, whatever) part of the DB for this purpose.
kprobst
No, the DAL is used only to pull the data from the database. That's the definition of DAL, unless you're confusing it with ORM.
kprobst
+3  A: 

"Data Acess Layer will have functions to check if username and password are correct" - wrong. The BLL will do that, the DAL will only retrieve (or try to retrieve) the user's information, without doing any checking on it.

Otávio Décio
so in this case, I am executing a SP, then where should I add Parameters to that SP, in BLL or DAL
vaibhav
Your BLL should ask the DAL to call the SP, and the BLL will interpret its results upon its return. The DAL is only a mostly brainless conduit.
Otávio Décio
so it means in BLL I will add parameters to that SP and pass it to DAL for execution.
vaibhav
No, the BLL knows nothing about SP's and parameters. The DAL should have a method that receive whatever parameters necessary and create the database call with such parameters.
Otávio Décio
Then what is the use of BLL here. I could have call function of DAL directly from Presentation Layer.
vaibhav
Yes you could, and that would be wrong.
Otávio Décio
+1  A: 

You should have something like this:

The UI calls BL.SaveUsernameAndPassword(string user, string pass);

BL.SaveUsernameAndPassword should validate the strings, and then call DAL.SaveUsernameAndPassword(string user, string pass);

DAL.SaveUsernameAndPassword should put these parameters into your SQL query and execute it, with the assumption that the data is valid

Fiona Holder
so in this case I can't have a common DAL for all my projects, as I have to write query in DAL.
vaibhav
Why does having to write the query in the DAL prevent you from having a common DAL for your projects?
Fiona Holder
In some projects I may want to select different number of variables from different tables.
vaibhav
Hmm, in that case then you should have a different DAL per project. The BL would then choose which DAL to use, depending on the project.
Fiona Holder
Your DAL should literally be a direct map onto your database. You don't want it to contain any logic, or do anything clever like map onto different databases, it just conveys data back and forth.
Fiona Holder