Monday, November 28, 2016

Blocks in N-Tier Application

Typically any n-tier application has following stacks:
  • Entities Layer  
    • This layer is always a single or a bunch of "Class Library"project type in Visual Studio. 
    • Contains all the entities used in all the other projects of the application. 
    • The classes in this layer represents table mapping from database (Entity framework LINQ to SQL), Data Transfer Objects (DTOs) or ASP.NET MVC Models. 
    • Most of the classes in this layer are POCO (Plain Old C# Objects) 
  • Data Access Layer
    • Some times referred as Persistence Layer.
    • This layer is represented by "Class Library" project type in Visual Studio.
    • Contains CRUD operations for items in database. 
    • You can use technologies like ADO.NET, LINQ to SQL, Entity Framework etc in this layer. 
    • The entities, database mapping classes needed for the CRUD operations will be referenced from the Entities Layer. 
    • Only Business Layer should have access to this layer. 
  • Business Components Layer
    • Sometimes also referred as Domain Layer.
    • This layer is represented by "Class Library" project type in Visual Studio.
    • Contains core functionality (converting arrays to lists, mathematical calculations or variable conversions) of the application. Basically holds the custom logic that is applied on the methods that are exposed from DAL before they are referenced in the Service Layer. In simple words this layer contains Repositories & UnitOfWork which are responsible of converting the Data objects into POCO Entities.
    • Entities needed for operations will be referenced from the Entities Layer and database operation methods will be referenced from  DAL.
    • Only Service Layer or Presentation Layer (In  case Service Layer is not present) should have access to this layer.
  • Services Layer
    • Also referred as  Application Layer.
    • This Layer provides ways to expose Business Components Layer as an API to third part systems.
    • This layer is either self hosted or hosted in web servers like IIS.
    • You can use technologies like WCF Service, Web Services, ASP.NET Web API in this layer.
    • This layer can only be shared with Presentation Layer or any other Third Party Systems.
    • This layer is required only when your application is sharing data with another system, else its not required.
  • Presentation Layer
    • This layer represents the user interface of the application.
    • This is hosted in web server like IIS.
    • To get the data from database, reference either Business Layer or Service Layer. Never ever make a direct call to database or DAL from this layer. 
    • You can use technologies like ASP.NET WebForms, ASP.NET MVC, AngularJS etc in this layer.
  • Common Components Layer
    • This layer is represented by "Class Library" project type in Visual Studio.
    • This is the optional layer, and cannot have dependencies in any of the above defined layers because this layer can be compiled and shared with multiple applications.  
    • Contains common libraries or functionalities that can be used in any of the above layers.
    • Example of some of the common functionalities are validation functionality, security libraries, encryption tools or exception logging classes.


My next post, shows all the above blocks in the form of a simple 2 page Bank Application using .NET Framework.

No comments:

Post a Comment