7

I read many articles talk about 3 tiers architecture in c# but i see that:

  • Almost use Bussiness Logic Layer(BLL) as a object mapping corresponding table in database. This BLL object has some methods like these:

    +GetData(): return this;

    +Update(this);

    +Insert(this);

    +Delete(this);

  • This BLL object calls corresponding DAL(Data Access Layer) to execute to corresponding table of database.

  • I think if with above methods, we can oly get a record and update it. But if we have got many records and want to put it into a dataset, how can we update all records changed? Must we use loop for all records to do that?
  • Moreover, in the database, there are many tables related to each other, so how can we put them into dataset, make relations and add, update, delete records like using BindingSource with a Combobox and a DataGridView? And how can we seperate code in this situation?
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Trần Minh
  • 1,633
  • 4
  • 15
  • 17

2 Answers2

12

enter image description here

The above describe a very simple architecture of a 3-tier model.

  1. DAL (Data Access Layer) interacts with Database directly, so all the SQL operation are being done within DAL only.
  2. BLL (Business Logic Layer) works like a mediator between DAL and the Presentation Tire.
  3. No direct communication is allowed between DAL and Presentation Layer.
  4. Although there is no physical presence of the Entity Layer, but Entity encapsulates all the information/data and passes it from one layer to the other.
  5. So all the Database object name and the Database Schema is being restricted inside the DAL which gives an extra security layer to the application.
  6. As Business rules/logics are being defined inside BLL, any update to business logic will not impact the DAL and the presentation layer

enter image description here

This diagram describes an actual implementation of a 3-tier model.

  1. Data Access Service and the Database Server can be hosted in single Server.
  2. Mostly SQL Server 2000/2005/2008 or Oracle can be hosted on Windows 2000/2003 Server.
  3. Business Server exposes all the operation through Web Service /Remoting/WCF.
  4. A highly configured server with Windows 2000/2003 can be used to host the Business Service, or else Microsoft BizTalk Server also can be used for this.
  5. Presentation Tier or the Client Consumes the Service exposed at Business Server by using the Proxy through http:// pipeline.
  6. Client can be any standalone machine with the application is being installed in case of Desktop Application (Win-Form or Console Application), or having a Browser to run Web Application.
  7. Data/Information are being encapsulated by entity and transferred from one location to another over network followed by all the network protocol.
Moiz
  • 2,409
  • 5
  • 27
  • 50
  • Thank a lot! I have understood more about 3 tiers and 3 layer architecture. Example,we have a table stores user informations, so each user mapped an entity. If we want to show all users into a datagridview and update all users which changed informations, must we encapsulate each Entity correspond each row (using loop) to update? Which is best way. Thank. Sorry because of my bad English – Trần Minh Dec 09 '12 at 13:04
  • The biggest "wrong layer" issue I've seen over the years is business-logic in the UI layer. A good rule of thumb is "if I had 2 presentations layers, would I have to duplicate the code I'm writing?" If so, move it to the business layer. – granadaCoder Feb 23 '17 at 14:56
4

There are 2 cool project about three tier architecture in C#.

3-tier architecture in C# and T̶h̶r̶e̶e̶ ̶L̶a̶y̶e̶r̶ ̶A̶r̶c̶h̶i̶t̶e̶c̶t̶u̶r̶e̶ ̶i̶n̶ ̶C̶#̶ ̶.̶N̶E̶T̶. Both projects are amazing specificly for you.

enter image description here

enter image description here

Juan
  • 4,910
  • 3
  • 37
  • 46
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • 1
    Thank you a lot. I have read 2 examples, i can understand somewhat a basic 3 layers architecture works. But they only provide an simple example with an object (user).If we use 'DataSet' to show all records, how can we update all records changed on 'DataSet', loop all records, don't we?. And if we have many objects relate to each other, which is best way to display data and update them together! Can you give me more complex examples! – Trần Minh Dec 09 '12 at 12:36
  • 1
    Both mentioned articles let the business logic layer depend (aka have a reference to) the dal layer. This is not the way to go. Your business model (aka domain model) should be the center of your application, the rest has references to the it. A good name for this is the Onion model. Google it, it is worth it! – Maarten Dec 09 '12 at 21:45
  • 2
    Onion architecture - http://jeffreypalermo.com/blog/the-onion-architecture-part-1/ – Maarten Dec 09 '12 at 21:47