The rule is: upper layer knows about lower layer but not vice versa. Presentation knows about BLL and not vice versa. BLL knows about DAL and not vice versa. Presentation has no idea about DAL and data store. BLL has no idea about data store. If lower layers
know about upper layers then this knowledge will poison the layers because they are not so common or general anymore. Just think - how complex will your BLL grow if it first has to know about Presentation layer that is web application and couple of months
later it has also to know about the other web application that offers web services and uses this same BLL.
Don't forget to mark solution providing post as "Answered".
I understand, but we are struggeling with BLL and DAL.
If I want to persist an object to an Access database, I need to create the query in the DAL.
And the values of the INSERT query must come from an BLL object.
Or is there another way?
Johan Theunissen MCPD, MCSE, MCTS BizTalk 2006
==============================
Please mark the most helpful reply/replies as "Answer".
You will need additional entity classes. For example, if you want to insert new customer you will create new instance of "Customer" class in your UI, populate all data and send it to DAL.
public class Customer
{
public int Id { get; set;}
public string FirstName { get; set;}
public string LastName { get; set;}
// ...
}
// UI will create and populate new customer instance
Customer customer = new Customer()
{
FirstName = txtFirstName.Text,
LastName = txtLastName.Text,
// ....
}
// And send it to business layer where you will perform validation etc.
BusinessLayer.Insert(customer);
// Then business layer will just forward this object to your DAL
CustomerDal.Insert(customer);
In fact, ObjectDataSource will do it for you if you specify "DataObjectTypeName" property.
Cheers,
M
Writing software would be a lot easier if it weren't for customers
Business objects must be known on almost all layers (there are special cases when you don't need them to be visible). Presentation layer must be able to create on initiate the creation of new objects, also it needs collections of objects returned as lists etc.
BLL, the place where business logic, services and operations are located, deals with same set of objects (or interfaces). And DAL has to know these classes (or interfaces) when it creates, saves or deletes objects.
Don't forget to mark solution providing post as "Answered".
Here's my $.10. Save yourself a ton of headache/performance and put your DAL inside of either the same assembly as your BLL or as part of the same business object unless you absolutely need to use 3-Tier. Otherwise, here are your options:
PL references BLL. BLL references an Entity assembly OR web service. DAL will reference the entity assembly/web service. You need the middle piece so that you don't have circular references. That middle piece will completely separate your DAL from your BLL
and also map your database to DTO/Entity. You will then have to extract out the DTO/Entity to your business object properties.
You can add another layer for doing the mapping if you'd like, but that's completly up to you. I believe Fowler uses a DataMapper pattern, but make sure you read the fine print :)
JohanNL
Participant
1644 Points
1227 Posts
BLL vs DAL
May 16, 2008 04:00 PM|LINK
What is best pratice?
a. BLL references DAL
b. DAL references BLL
c. BLL references DAL and DAL references BLL
MCPD, MCSE, MCTS BizTalk 2006
==============================
Please mark the most helpful reply/replies as "Answer".
yeotumitsu@s...
Contributor
4907 Points
836 Posts
Re: BLL vs DAL
May 16, 2008 05:47 PM|LINK
N- Tier Architecture always follow a sequence of interaction -
User - UI - BLL - DAL - Data Base
and vice versa.
BLL always refer to DAL for any data access and DAL returns data/dataset/array or any data format to BLL.
============================
Please ask if you need examples.
-Manas
=======================================
If this post is useful to you, please mark it as answer.
DigiMortal
Contributor
5658 Points
939 Posts
MVP
Re: BLL vs DAL
May 19, 2008 08:54 AM|LINK
Also visit my ASP.NET blog or follow me @ Twitter:twitter.com/gpeipman
JohanNL
Participant
1644 Points
1227 Posts
Re: BLL vs DAL
May 19, 2008 02:44 PM|LINK
I understand, but we are struggeling with BLL and DAL.
If I want to persist an object to an Access database, I need to create the query in the DAL.
And the values of the INSERT query must come from an BLL object.
Or is there another way?
MCPD, MCSE, MCTS BizTalk 2006
==============================
Please mark the most helpful reply/replies as "Answer".
Momcilo
Participant
1477 Points
251 Posts
Re: BLL vs DAL
May 19, 2008 03:28 PM|LINK
You will need additional entity classes. For example, if you want to insert new customer you will create new instance of "Customer" class in your UI, populate all data and send it to DAL.
public class Customer { public int Id { get; set;} public string FirstName { get; set;} public string LastName { get; set;} // ... } // UI will create and populate new customer instance Customer customer = new Customer() { FirstName = txtFirstName.Text, LastName = txtLastName.Text, // .... } // And send it to business layer where you will perform validation etc. BusinessLayer.Insert(customer); // Then business layer will just forward this object to your DAL CustomerDal.Insert(customer);In fact, ObjectDataSource will do it for you if you specify "DataObjectTypeName" property.
Cheers,
M
JohanNL
Participant
1644 Points
1227 Posts
Re: BLL vs DAL
May 20, 2008 07:55 AM|LINK
But the customer object needs to be recognized in the DAL, so the DAL needs a reference to the BLL, or not?
MCPD, MCSE, MCTS BizTalk 2006
==============================
Please mark the most helpful reply/replies as "Answer".
N.Ziember
Member
55 Points
25 Posts
Re: BLL vs DAL
May 20, 2008 08:46 AM|LINK
The way I did it, was that all three layers have a reference to the BusinessObjects namespace where the objects themselves are declared.
Not directly related to any layer, but accessible by all of them.
/NZ
DigiMortal
Contributor
5658 Points
939 Posts
MVP
Re: BLL vs DAL
May 20, 2008 11:03 AM|LINK
Also visit my ASP.NET blog or follow me @ Twitter:twitter.com/gpeipman
JohanNL
Participant
1644 Points
1227 Posts
Re: BLL vs DAL
May 20, 2008 12:45 PM|LINK
So the BO layer is more like a vertical layer, next to the vertical UI + BLL + DAL?
MCPD, MCSE, MCTS BizTalk 2006
==============================
Please mark the most helpful reply/replies as "Answer".
czuvich
Participant
886 Points
344 Posts
Re: BLL vs DAL
May 20, 2008 01:06 PM|LINK
Here's my $.10. Save yourself a ton of headache/performance and put your DAL inside of either the same assembly as your BLL or as part of the same business object unless you absolutely need to use 3-Tier. Otherwise, here are your options:
PL references BLL. BLL references an Entity assembly OR web service. DAL will reference the entity assembly/web service. You need the middle piece so that you don't have circular references. That middle piece will completely separate your DAL from your BLL and also map your database to DTO/Entity. You will then have to extract out the DTO/Entity to your business object properties.
You can add another layer for doing the mapping if you'd like, but that's completly up to you. I believe Fowler uses a DataMapper pattern, but make sure you read the fine print :)