Sunteți pe pagina 1din 30

Home

Career Advices

Articles

Beginners

Videos

Interviews

Forums

Codes

Blogs

Catalog

Microsoft MVP | Tutorials - ASP.NET, Silverlight, more | Downloads | Quick Links | Top Posts | Top Performers | .NET Feeds | Bookmarks Online : 25027 | Welcome, Guest! Login

>> .NET How to Tips and Tricks eBook, Project Cod

Home > Articles > ASP.NET > 4-Tier Architecture in ASP.NET with C#

Thanks to our Article Writing Competition Sponsors NDepend Nevron Software Nukeation Pluralsight.com LearnVisualStudio.NET 10Tec FPS Components Questpond ITFunda

Also read .NET Interview Questions | Calling methods of different classes into same Transaction Pattern in C#.NET | ASP.NET Tutorials

Submit Article |

Search Artic

4-Tier Architecture in ASP.NET with C#

Posted by SheoNarayan on 10/22/2007 | Views: 106307 | Category: ASP.NET | Level: Inte

Winners announced ! (Email has been sent to all the winners, please respond ASAP)

@DotNetFunda
488+ Web Development Tips & Tricks Articles Categories .NET Framework Articles ADO.NET Articles ASP.NET Articles ASP.NET AJAX Articles ASP.NET MVC Articles Azure Articles Best Practices Articles BizTalk Server Articles C# Articles CMS Articles CSS Articles Error and Resolution Articles F# Articles JavaScript Articles Top Articles Authors

Code Updated on 21st April 2008 to support Sorting, Paging and data manipulation through Stored Procedure in DAL Almost all of us must have heard about 3-Tier architecture but what is this 4-Tier architecture? What are the benefits and how it is different from other architectures? Download
Download source code for 4-Tier Architecture in ASP.NET with C#

Well, the architecture I am going to demonstrate here is just enhancement of 3 need of writing long function parameters throughout the layers (as in traditional objects of the application will be in a separate tier so that in future you can separ Change in the object definition can be done without touching the entire Business A

Let me explain you step-wise process of creatioin of 4-Tier architecture application

In this application, I am going to take example of a Person that will have 3 prop create a separate pages to insert these records (default.aspx) into database and database. In this application we will have following 4-Tiers

Mon, 11-Jul-2011 Authors

1. 2. 3. 4.

Business Object [BO] Business Access Layer [BAL] Data Access Layer [DAL] UI (4-Tier) folder [UI]

250

250

All Time Authors

Picture - 1 (Solution Explorer)

12250

9350

6450

5950

5500

3500

More ...
(Statistics delayed by 5 minutes)

Advertisement

.NET How to Tips and Tricks A new and quick way to learn & enhance .NET knowledge by solving real time problems in .NET technologies. This ".NET How to Tips and Tricks" contains solutions of hundreds of real time problems. All How to Tips and Tricks are supported by Video tutorials, Demo projects with source code and To-the .. more details ... ASP.NET 4.0 - Complete Web Development Training ASP.NET 4.0 using Visual C# 2010 - A Complete Web development online classroom training. After going through this training, you will have knowledge of HTML, JavaScript, CSS, ASP.NET, C# that will help you to work on any kind of web development projects using ASP.NET. more details ... ASP.NET How to Tips and Tricks This ASP.NET How to Tips and Tricks has solutions of hundreds of real time ASP.NET related problems that you face Announcements

For simplicity reason, I have created separate folders for first 3-tiers into App projects for these tiers and add into forth tier (UI) solution. Get hundreds of ASP.NET Tips and Tricks http://www.itfunda.com/aspnet-how Lets create above tiers one by one.

Business Object [BO - Person.cs]

Create a separate folder by right-clicking App_Code folder and name it as BO. R (Class) file named Person.cs. Write following code inside it.

int m_PersonID = 0; string m_FirstName = string.Empty; string m_LastName = string.Empty; int m_Age = 0;

#region Propertiers public int PersonID { get { return m_PersonID; } set { m_PersonID = value; } }

DotNetFunda
en Facebook Me gusta

public string FirstName { get { return m_FirstName; }

A 1,082 personas les gusta DotNetFunda.

set { m_FirstName = value; } }

Sandeep

Swarna

Piyush

public string LastName { get { return m_LastName; }

Winners

set { m_LastName = value; } }

public int Age { get { return m_Age; }


Winners & Prizes Advertisement

set { m_Age = value; } } #endregion Properties

Here, we are first declaring 4 variables for corresponding properites and defining Object with all its properties/attributes to work with. Next step is to create Data Ac

Data Access Layer [DAL - PersonDAL.cs]


The way you created BO folder inside App_Code folder, create another folder it as PersonDAL.cs Write following code inside it (You can copy-paste).

using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security;

Ads by Google

using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;

/// <summary>

Security for Developers


Powerful encryption and security components for your applications
www.EldoS.com/SecureBlackbox

/// Summary description for PersonDAL /// </summary> public class PersonDAL {

string connStr = ConfigurationManager.ConnectionStrings["TutTestConn"].T

public PersonDAL() {

/// <summary> /// Used to insert records into database /// </summary> /// <param name="p"></param> /// <returns></returns> public int Insert(Person person) { SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlCommand dCmd = new SqlCommand("InsertData", conn); dCmd.CommandType = CommandType.StoredProcedure; try { dCmd.Parameters.AddWithValue("@firstName", person.FirstName);

dCmd.Parameters.AddWithValue("@lastName", person.LastName); dCmd.Parameters.AddWithValue("@age", person.Age); return dCmd.ExecuteNonQuery(); } catch { throw; } finally { dCmd.Dispose(); conn.Close(); conn.Dispose(); } }

/// <summary> /// Update record into database /// </summary> /// <param name="p"></param> /// <returns></returns> public int Update(Person person) { SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlCommand dCmd = new SqlCommand("UpdateData", conn); dCmd.CommandType = CommandType.StoredProcedure; try { dCmd.Parameters.AddWithValue("@firstName", person.FirstName); dCmd.Parameters.AddWithValue("@lastName", person.LastName); dCmd.Parameters.AddWithValue("@age", person.Age);

dCmd.Parameters.AddWithValue("@personID", person.PersonID); return dCmd.ExecuteNonQuery(); } catch { throw; } finally { dCmd.Dispose(); conn.Close(); conn.Dispose(); } }

/// <summary> /// Load all records from database /// </summary> /// <returns></returns> public DataTable Load() { SqlConnection conn = new SqlConnection(connStr); SqlDataAdapter dAd = new SqlDataAdapter("LoadAll", conn); dAd.SelectCommand.CommandType = CommandType.StoredProcedure; DataSet dSet = new DataSet(); try { dAd.Fill(dSet, "PersonTable"); return dSet.Tables["PersonTable"]; } catch { throw;

} finally { dSet.Dispose(); dAd.Dispose(); conn.Close(); conn.Dispose(); } }

/// <summary> /// Delete record from database /// </summary> /// <param name="person"></param> /// <returns></returns> public int Delete(Person person) { SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlCommand dCmd = new SqlCommand("DeleteData", conn); dCmd.CommandType = CommandType.StoredProcedure; try { dCmd.Parameters.AddWithValue("@personID", person.PersonID); return dCmd.ExecuteNonQuery(); } catch { throw; } finally { dCmd.Dispose();

conn.Close(); conn.Dispose(); } }

In this class file, we have Insert, Update, Delete, Load methods. In this class fil from the web.config file in a class level variable called connStr and using the sa connection.

For simplicity reason, I have not shown the code for Stored Procedure database and code by downloading the Source Code files. This was your D Business Object and Data Access Layer ready. Now lets go to the third layer and

Business Access Layer [BAL - PersonBAL.cs]

Again, right click App_Code folder and add a new folder named BAL. Create a PersonBAL.cs. Write following code inside it.

using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;

/// <summary> /// Summary description for PersonBAL /// </summary> public class PersonBAL { public PersonBAL() {

/// <summary> /// insert records into database /// </summary> /// <param name="person"></param> /// <returns></returns> public int Insert(Person person) { PersonDAL pDAL = new PersonDAL(); try { return pDAL.Insert(person); } catch { throw; } finally { pDAL = null; } }

/// <summary> /// Update records into database /// </summary> /// <param name="person"></param> /// <returns></returns> public int Update(Person person) { PersonDAL pDAL = new PersonDAL();

try { return pDAL.Update(person); } catch { throw; } finally { pDAL = null; } }

/// <summary> /// Load records from database /// </summary> /// <returns></returns> public DataTable Load() { PersonDAL pDAL = new PersonDAL(); try { return pDAL.Load(); } catch { throw; } finally { pDAL = null; }

/// <summary> /// Delete record from database /// </summary> /// <param name="person"></param> /// <returns></returns> public int Delete(Person person) { PersonDAL pDAL = new PersonDAL(); try { return pDAL.Delete(person); } catch { throw; } finally { pDAL = null; } }

Here, we are creating separate methods each for respective PersonDAL.cs metho business logic, so we are just instantiating the Data Access Layer objects, using it layer, described later on).

You must have noticed here that in the try catch block, I am just writing throw; will occur it will be send to the calling layers (in our case UI) and there we will han Till now, we have BO, BAL and DAL ready. Now we are left with our application file that will contain one form and textboxs that will be used to enter records.

User Interface - [UI]-Default.aspx

Create a separate folder in your UI solution named 4-Tier and add one .aspx pag page, we will write ASP.NET code to render textboxes and buttons. OnClick even method that will ultimately insert the records into database. Below is the code to r

<form id="form1" runat="server"> <div> <p><a href="List.aspx">List Records</a></p> <asp:Label ID="lblMessage" runat="Server" ForeColor="red"

EnableViewState="False"></asp:Label> <table style="border:2px solid #cccccc;"> <tr style="background-color:#ECF3AB;"> <th colspan="3">Add Records</th> </tr> <tr> <td> First Name: </td> <td>

<asp:TextBox ID="txtFirstName" runat="Server"></asp:Text </td> <td>

<asp:RequiredFieldValidator ID="req1" runat="Server" Tex

ControlToValidate="txtFirstName" Display="dynamic"></asp:RequiredFieldValida </td> </tr> <tr> <td> Last Name: </td> <td>

<asp:TextBox ID="txtLastName" runat="Server"></asp:TextB </td> <td>

<asp:RequiredFieldValidator ID="req2" runat="Server" Tex

ControlToValidate="txtLastName" Display="dynamic"></asp:RequiredFieldValidat </td> </tr> <tr> <td> Age: </td> <td>

<asp:TextBox ID="txtAge" runat="Server" Columns="4"></as </td> <td>

<asp:RequiredFieldValidator ID="req3" runat="Server" Tex ControlToValidate="txtAge"

Display="dynamic"></asp:RequiredFieldValidator>

<asp:CompareValidator ID="Comp1" runat="Server" Text="On

ControlToValidate="txtAge" Operator="DataTypeCheck" Type="Integer"></asp:Com </td> </tr> <tr> <td> </td> <td> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="AddRecords" /> </td> </tr> </table> </div>

</form>

Picture - 2 (Default.aspx)

AddRecords method

protected void AddRecords(object sender, EventArgs e) { //Lets validate the page first if (!Page.IsValid) return;

int intResult = 0; // Page is valid, lets go ahead and insert records // Instantiate BAL object PersonBAL pBAL = new PersonBAL(); // Instantiate the object we have to deal with Person person = new Person(); // set the properties of the object person.FirstName = txtFirstName.Text; person.LastName = txtLastName.Text;

person.Age = Int32.Parse(txtAge.Text);

try { intResult = pBAL.Insert(person); if (intResult > 0) lblMessage.Text = "New record inserted successfully."; else

lblMessage.Text = "FirstName [<b>"+ txtFirstName.Text +"</b> another

name";

} catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { person = null; pBAL = null; } }

In the above method, I am doing following things mainly: 1. Instantiating BAL object 2. Instantiating BO object 3. Settinng properties of BO object by the textbox values 4. Calling Insert method of the BAL object and passing BO object as parameter [pB 5. Checking for number of records affected, If the number is more than zero, Duplicate records found. 6. If any layer will throw any error, I am catching it and displaying to the user in t 7. Whatever objects I had instantiated, I am specifying their values to null to use them.

User Interface - [UI]-List.aspx

In this page, I am going to use a GridView to List, Modify, Sort and Delete record in the same 4-Tier folder named List.aspx (Picture - 3). Following is the code for t for us.

<form id="form1" runat="server"> <div> <p><a href="Default.aspx">Add Record</a></p> <asp:Label ID="lblMessage" runat="Server" ForeColor="red" EnableViewState="False"></asp:Label>

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColo GridLines="None"

DataKeyNames="PersonID" AutoGenerateEditButton="True" AutoGenerateC OnRowEditing="EditRecord" OnRowUpdating="UpdateRecord" OnRowCancelingEdit="CancelRecord"

OnRowDeleting="DeleteRecord" AllowPaging="True" AllowSorting="tru OnPageIndexChanging="ChangePage" OnSorting="SortRecords">

<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="Whi <RowStyle BackColor="#EFF3FB" /> <EditRowStyle BackColor="#2ff1BF" />

<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor

<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlig

<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="Whi <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="PersonID" HeaderText="Person ID" SortExpression="PersonID" />

<asp:TemplateField HeaderText="First Name" SortExpression="F <ItemTemplate> <%# Eval("FirstName") %> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtFName" runat="Server" Text='<%# >'></asp:TextBox> </EditItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Last Name" SortExpression="La <ItemTemplate> <%# Eval("LastName") %> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtLName" runat="Server" Text='<%# >'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Age" SortExpression="Age"> <ItemTemplate> <%# Eval("Age") %> </ItemTemplate> <EditItemTemplate>

<asp:TextBox ID="txtAge" runat="Server" Text='<%# Ev >'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Delete?"> <ItemTemplate>

<span onclick="return confirm('Are you sure to Delet

<asp:LinkButton ID="lnBD" runat="server" Text="D CommandName="Delete"></asp:LinkButton> </span> </ItemTemplate> </asp:TemplateField>

</Columns> </asp:GridView> </div> </form>

Picture - 3 (List.aspx)

On the OnRowEditing, OnRowUpdating, OnRowCancelEdit, OnSorting and OnRow methods to do data manipulation. Following are codes to bind the GridView and m

protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) BindGrid(); }

/// <summary> /// Fired when Cancel button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param>

protected void CancelRecord(object sender, GridViewCancelEditEventArgs e { GridView1.EditIndex = -1; BindGrid(); }

/// <summary> /// Fires when Edit button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void EditRecord(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; BindGrid(); }

/// <summary> /// Fires when Update button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void UpdateRecord(object sender, GridViewUpdateEventArgs e) {

int personID = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToSt int intResult = 0; GridViewRow row = GridView1.Rows[e.RowIndex];

TextBox tFN = (TextBox) row.FindControl("txtFName"); TextBox tLN = (TextBox)row.FindControl("txtLName"); TextBox tAge = (TextBox)row.FindControl("txtAge");

// instantiate BAL PersonBAL pBAL = new PersonBAL(); Person person = new Person(); try { person.PersonID = personID;

person.FirstName = tFN.Text; person.LastName = tLN.Text; person.Age = Int32.Parse(tAge.Text); intResult = pBAL.Update(person); if (intResult > 0) lblMessage.Text = "Record Updated Successfully."; else lblMessage.Text = "Record couldn't updated"; } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { person = null; pBAL = null; }

GridView1.EditIndex = -1; // Refresh the list BindGrid(); }

/// <summary> /// fires when Delete button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DeleteRecord(object sender, GridViewDeleteEventArgs e) {

int personID = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToSt

// instantiate BAL PersonBAL pBAL = new PersonBAL(); Person person = new Person(); try { person.PersonID = personID; pBAL.Delete(person);

lblMessage.Text = "Record Deleted Successfully."; } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { person = null; pBAL = null; }

GridView1.EditIndex = -1; // Refresh the list BindGrid(); }

/// <summary> /// Fires when page links are clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ChangePage(object sender, GridViewPageEventArgs e) {

GridView1.PageIndex = e.NewPageIndex; // Refresh the list BindGrid(); }

/// <summary> /// Fires when Columns heading are clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SortRecords(object sender, GridViewSortEventArgs e) { DataTable dataTable = GridDataSource();

if (dataTable != null) { DataView dataView = new DataView(dataTable);

dataView.Sort = GetSortExpression(e);

GridView1.DataSource = dataView; GridView1.DataBind(); } }

#region Private Methods

/// <summary> /// Bind the gridview /// </summary> private void BindGrid() { GridView1.DataSource = GridDataSource();

GridView1.DataBind(); }

/// <summary> /// Get GridView DataSource /// </summary> private DataTable GridDataSource() { PersonBAL p = new PersonBAL(); DataTable dTable = new DataTable(); try { dTable = p.Load(); } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { p = null; }

return dTable; }

/// <summary> /// Get sort expression for the gridview /// </summary> /// <param name="e"></param> /// <returns></returns> private string GetSortExpression(GridViewSortEventArgs e) {

string sortDirection = string.Empty; // if clicked on the same column twice then let it toggle the sort ascending if (ViewState["SortExpression"] != null) {

if (!ViewState["SortExpression"].ToString().Equals(e.SortExpress { ViewState["SortDirection"] = null; } }

if (ViewState["SortDirection"] != null) { if (ViewState["SortDirection"].ToString().Equals("ASC")) { sortDirection = "DESC"; ViewState["SortDirection"] = "DESC"; } else { sortDirection = "ASC"; ViewState["SortDirection"] = "ASC"; } } else { ViewState["SortDirection"] = "ASC"; } ViewState["SortExpression"] = e.SortExpression.ToLower();

return e.SortExpression + " " + sortDirection; } #endregion Private Methods

Thats it!!!

Now we have done all our home work, Its time to enjoy now. Just build the shows Build Succeeded in the status bar at the bottom, you are ready to enjoy you

Browse it as http://localhost/4-Tier (Provided you have created "4-Tier" virtual di own virtual directory name), you should see your screens as shown above (default

Try manipulating data and see how effectively its happening. This was a simple can create larger application by adding separate objects and their corresponding ti

In order to use namespace in different tiers, you should define your namespace namespace by using statement whereever you need.

I have also attached a ready to use sample code of this example, Download it and Thanks & Happy Coding.
SQL Server SSIS Tasks SSIS Tasks for AS2, SFTP, FTPS, POP3, IMAP, SMTP, SSH, OFTP, etc .netCART for ASP.NET shopping cart with real-time ship / payment processing and free trial. Promocin Oferta del da Todos los das una Sper Oferta. Regstrate ahora y recibe tu cupn.

If you like this article, subscribe to our Forums section.


Found interesting? Add this to:

RSS Feed. You can also subscribe via em

2
| More | Bookmark

Please Sign In to vote for this post. >> Write Response - Respond to this post and get points

About Sheo Narayan


Experience: Home page: Member since: Level: Status: Biography:

8 year(s) http://www.snarayan.com Tuesday, July 08, 2008 HonoraryPlatinum [Administrator] Author, Writer, Mentor & architecting applications since year ASP.NET How to solutions 101+ jQuery How to's method ASP.NET AJAX Tutorials ebook

Latest Articles from the Author SheoNara

Button Tips and Tricks Part-I TextBox Tips and Tricks Part-III TextBox Tips and Tricks Part-II TextBox Tips and Tricks Part-I How to bind dropdownlist with databas

More ... Latest Articles

To view full viewname in sharepoint ASP.NET 4.0 Routing Using Xml file With the Gridview and Te Extensions Methods (Part I) in .NET Fra A Wonderful Experience of a winner in DotNetFunda.com

More ...

Responses
Posted by: Tbroyer | Posted on: 24 Oct 2007 12:18:46 AM

Your BO "tier" is what I call a set of DTOs (Data Transfer Objects), it's neither new nor a "tier": DTOs ar have no embedded "business logic", they're just data "containers".

Author's response: Please see the 2nd paragraph of this article. It explains the purpose and its benefits. Posted by: Wesc | Posted on: 24 Oct 2007 06:11:00 AM

This is normal, everyday 3-tier: Presentation, BLL, and DAL. The object you're passing back and forth is be. But, it's a fine article for someone who wants a simple explanation of DTOs.

Author's response: Please see the 2nd paragraph of this article. It explains the purpose and its benefits. Posted by: Damieng | Posted on: 26 Oct 2007 12:52:33 AM

This sample suffers from both SQL injection and HTML injection making it a very insecure. Get rid of bui queries and ensure that output added to the HTML is correctly HttpUtility.Encoded.

Author's response: Thanks for your feedback Damieng. Sql statement has been used here to make the t Regards Posted by: Amitgupta007_99 | Posted on: 26 Oct 2007 05:19:16 AM

Basically, it's all about components. If the UI (presentation) logic is mixed up with the business (task) lo slog through all that code and filter out the business code from the presentation code. But if you put the easily plug your business code into any type of user interface or API.

Think of each tier as a black box that only has functionality that is related to what it needs to do. The tie above it's move a physical tiers.When it comes to performance this would be very very fast and scalable

There's more to it, of course, but that's the basic principle Software evolves. Build it for evolution, exten architecture will helps us a great deal in improving the future of application. Amit P Gupta Web Strategist amit@r2ainformatics.com

Posted by: Vijay.a.nikam | Posted on: 02 Dec 2007 01:06:57 AM Good one Posted by: Vijay.a.nikam | Posted on: 28 Jan 2008 07:51:37 AM

Hello, This is very good article. I have some questions. 1. Where to maintain transaction. 2. If I am using inheritance. Then their is need to create a diffent DAL classes base class and each deriv

Posted by: Ravimama | Posted on: 11 Apr 2008 06:06:15 AM Consider your BO, you have member variables. Why not expose them as public variables? What is the exact purpose of using the properties? Sorry if my question is too dumb. But I want to get things clear. Posted by: SheoNarayan | Posted on: 11 Apr 2008 10:01:30 AM Hi Vijay.a.nikam, For your point 1 - You can use transaction in Data Access Layer. Point 2 - I couldn't get you.

Posted by: SheoNarayan | Posted on: 11 Apr 2008 10:04:41 AM HI Ravimama, To answer your question, I will suggest to visit following link http://www.developersdex.com/csharp/message.asp?p=1111&r=6148128 http://www.eggheadcafe.com/software/aspnet/31582165/getset-vs-public-variabl.aspx http://channel9.msdn.com/ShowPost.aspx?PostID=299396 Thanks Posted by: Akeenlearner | Posted on: 31 May 2008 11:07:54 PM Hi, this is good, thanks. But i have a concern. I am speaking from a Windows App point of view but

Supposedly, you have created separate project for each of the Layers. Let's just say the BO and BAL are have to add reference to it. However this would result in a circular dependency which is not allowed. If result in a error that you have made more than a file reference to a assembly when you reference the a

I am referring to your statement when you mentioned "You can create a separate projects for these tier Thanks, I'm still learning Posted by: SheoNarayan | Posted on: 01 Jun 2008 10:51:30 PM Hi Akeenlearner,

Thanks for your response. If you are creating separate project for all these layers, you will need followin

1. You will need to create separate projects for all layers BO, BAL, DAL, UI. 2. You will need to add reference of BO into all UI, BAL and DAL. If you will have BO and BAL into same 3. Your BO is nothing but a your object Entities layer that will work as a passing objects from one layer all entities of your application) Please let me know if you have still some question. Posted by: Giff2005 | Posted on: 11 Jul 2008 02:15:11 AM

Any real world application has Business Logic. This does not fit into the above 4 tiers, necessitating anot Layer or BLL. Am I wrong or does this meam an implementation of the above would really be a 5 seem a bit redundant. Could there just be a DataBaseController class that takes the BOL object as a par operations. Posted by: SheoNarayan | Posted on: 11 Jul 2008 04:33:23 AM Hi Giff2005,

I guess what you are calling a BLL is nothing but BAL represented here. So all your business logic if any Thanks Posted by: Chchinmaya | Posted on: 18 Jul 2008 03:20:31 AM Hi This is chinmaya i understand alot from this article ......... Thank u for ur information Posted by: Rumana | Posted on: 25 Aug 2008 12:17:25 AM Hi, I understood the four tier architecture . but can u help me how to use design pattern(strategy pattern) please reply.... Posted by: SheoNarayan | Posted on: 25 Aug 2008 12:51:45 AM This is not your exact answer but something that can help you.

I think I won't be able to explain these things in details right now, but you can visit http://www.develop know about Strategy Design pattern that might help you to design yourself. Will try to write article on it in future. -Regards, Sheo Narayan Posted by: Jijojosephk | Posted on: 01 Apr 2010 12:47:57 AM Hi Sheo,

I'm not a well experienced person but I have one concern. Can't we create a common DAL rather than c if I'm wrong. Regards, Jijo

Posted by: SheoNarayan | Posted on: 01 Apr 2010 01:35:16 AM @Jijojosephk

Yes, you can do that however creating all methods related with respective BLLs will complicate your DAL projects). However you can have your DAL classes and to communicate with the database you can create a Hope this helps. Thank you. Posted by: Ko_min_min | Posted on: 14 Jul 2010 02:35:54 PM if you have to put each tier in seperate machine, how can you do it?

Posted by: SheoNarayan | Posted on: 14 Jul 2010 10:06:19 PM

@Ko_min_min: I do not think its by default possible to keep different tiers in separate machine, however you can use re to spread the load of different tiers on different machines.

In general this is not done instead several servers are hosted with same application using load balancer Thank you Posted by: Ray.chayan | Posted on: 21 Aug 2010 10:00:52 AM | Points: 10

Hi Sheo , I have worked in 3 tire architecture but this is new to me. Thanks 4 this. But I have some confusion about the use of BO and BAL tires. In three tire we use 1 business object lay tires. how this step modify our application and which respect? Posted by: Mukesh.chaware@dana.com | Posted on: 14 Feb 2011 06:51:30 AM | Points: 25 Hi Sheo, I wonder if you are still active on this post. Nevertheless, it is a good post capturing the basics of 4 n-tier.

Usually the .config file of the DAL project will be containing the connection-string and other such details having higher-privilege rights can just go to appropriate path -- right click on the config file -- open in n username/password of DB from connection string and other such details. What is the best-practice you follow to overcom such a limitation? --Regards, Mukesh

Posted by: SheoNarayan | Posted on: 14 Feb 2011 07:36:31 AM | Points: 25 Hi Mukesh,

Yest they can go and open the .config file in notepad and see them. To overcome this problem, you can that should help you http://msdn.microsoft.com/en-us/library/ff647398.aspx.

Thanks Posted by: JhunCa | Posted on: 28 Feb 2011 05:59:07 PM | Points: 25

Dear All, I am very new in ASP.Net, do you think I should make a class or what you called BO, DAL, BAL and UI f Let say, I have tables for my Contact Database and they are Employee , Customer and Profile and UI for each table in my database? Could you please answer and I would be very grateful if you answer my questions immediately. Thanks and more power to DotNetFunda and the contributors also. Jhun Ca. Posted by: Vaniy | Posted on: 29 Apr 2011 03:34:47 PM | Points: 25 Hi Sheo, if you are still active in this article, can u plz explain me.

you have used Person object to insert,update and delete and why have you used datatable for listing an objects to bind to Grid, so we will be using BO in all situtation. is it bcoz data table is convinient in sortin Thanks Posted by: SheoNarayan | Posted on: 30 Apr 2011 03:29:17 PM | Points: 25 Hi Vaniy,

You are correct, just to quickly put together I have used DataTable. Ideally we can use generic list objec BAL and populate it to the Grid.

This article was written way back in 2007 and I guess at that time we were started talking about Generi support sorting and paging as well through LINQ to it would be much easier. Thanks!

Posted by: Siva@88 | Posted on: 23 May 2011 09:51:42 PM | Points: 25

hi sheo, Can you please send me the code for search button in list.aspx to retrive one row from database.this wi Thanks in Advance. Mail address: sivarajan.kanakasabai@gmail.com Free Ajax Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature deploy. Download Now!

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.

Copyright DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 7/11/2011 10:06:08 AM

S-ar putea să vă placă și