Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implementing a 3 tier architecture 1

Status
Not open for further replies.

Tokhra

Programmer
Oct 1, 2003
134
ES
Hey all,

What's the standard practice for implementing a 3 tier architecture with asp.net? i've tried to seperate my business and data layers, but im struggling with the communication between layers - since I can't pass the business object by ref to the data layer because that causes a circular reference between the libraries.

So I tried creating another library of interfaces, so:

Project.Business references Project.Business.Interfaces, Project.Data

and

Project.Data references Project.Interfaces

then

Project (presentation) references Project.Business

This did the trick to a point, but im now encountering problems with it, for instance take the following method:

Code:
// Project.Data.GetCustomers(); 
public static ICustomerCollection GetCustomers(ref ICustomerCollection customers, int storeID) 
{ 
    // data stuff 
    while(reader.Read()) 
    { 
        ICustomer customer = ???? 
        customer.CustomerID = (int) reader["CustomerID"]; 
        // And so on 

        customers.Add(customer); } 
}

The problem there is that I cannot initiate a instance of an interface to put into the collection, and I cannot initiate an instance of the real class because I cannot reference Project.Business from Project.Data, argh!

The interfaces seemed to be an OK method, until I reached that point.

Previously to the nightmare with architectures im currently experiencing, id just have a Customer object, which would encapsulate everything to do with the Customer, including data access. So effectively my business and data layers would be combined. Im thinking of going back to this, although I like the idea of seperation.

I notice that alot of people pass DataSet's and SqlDataReaders between layers, I don't like the DataSet method because its messy, and isn't good for passing a single value, and SqlDataReaders hold the connection until closed - which is obviously not the best thing to do. So I was considering passing XML between layers - what with standards and everything I thought this would be good, but i've been advised that this causes a big performance overhead.

So what am I to do? Can anyone please shed some light on my architecture problems before I go mad

I look forward to any responses,

Thanks,
Matt.
 
since I can't pass the business object by ref to the data layer because that causes a circular reference between the libraries.

This indicates that you need to separate out your communications objects into their own assembly. It can then be referenced by both layers without any circularity.

Previously to the nightmare with architectures im currently experiencing, id just have a Customer object, which would encapsulate everything to do with the Customer, including data access.

In this case, you'd have your business entities (data values only) in one class, and the methods to read/write them to the database in a separate class. The business entites form what is commonly known as a DTO (Data Transfer Object), and the DB class forms a DAL (Data Access Layer). This structure violates what most people are taught about objects, but it's needed when you have to store collections of objects.

A good book to read is Martin Fowler's Enterprise Application Architecture. It's fairly expensive, but it's one of those titles that you'll use for years.

Using XML to pass between layers does give you some flexibility, but as those others have pointed out, it can be slow.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Wrox ASP.NET Website Programming - Problem, Design, Solution is a 3-tier book, too.
The whole book is one sample C# ASP.NET app. I'm using it as the code foundation for my real web app. It's quite mid-level, they don't explain the simple stuff. You could even download the code for the book without buying the book. The VB version is tighter than the C# version.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top