This site uses cookies to bring you the best experience. Find out more
Skip to main content

blog

Integrating N-TIER Architecture into C# Applications

Having recently introduced more code reviewing during our projects, we have taken a step forward to improve the structure of our web applications. Historically we have used a very simple client-server architecture that was suitable for single developers and the types of application we were developing. With our solutions becoming more complex and the development team growing, we needed something that would make development more structured and efficient.

So we have moved to an N-Tier architecture incorporating 3 main tiers and a data source, which are depicted in the diagram below;

These Tiers broadly conform to the Tiers in a typical N-Tier architecture, but I have defined below what they mean to us;
 

  • Presentation Tier – this is strictly the user interface
  • Service Tier – this tier contains all the services including data services that get data from the data access layer
  • Data Access Tier – this tier accesses data from the data source and passes it to the services
  • Data Source – this can be anything from a SQL database to csv file or a spreadsheet
     

We predominantly deal with SQL databases as our Data Source, using Entity Framework to map the database structure into the C# application. In our Data Access Tier we use the repository pattern. Although Entity Framework DbSets can be used as the repositories for all entities, we have created a wrapper around it to avoid dependency on Entity framework in our Service Tier. The wrapper we have created around Entity Framework is a generic repository which has common methods to retrieve data, because it’s generic, we don’t have to create a repository for each entity.

The power of this setup is in the flexibility to handle changes to the Data Access Layer, for example changing from a SQL database to an Excel spreadsheet, only requires changes to the repository in the Data Access Layer, which would then point to a different data source.

This architecture allows you to handle technology changes very easily. For example we’ve separated our core business logic (in the Service Tier) from the Presentation Tier, which allows us to reuse it if we move to a different frontend technology. So if we had a Silverlight front end that we wanted to upgrade to MVC we would just need to change the Presentation Tier. The architecture also allows us to have multiple client applications. We can have a mobile application and a web application pointing to the same Service Tier.

In conclusion, this architecture makes our applications more flexible, maintainable, and testable and allows bigger development teams to work together more easily.This is a simple 3 tier architecture we are using, but as our applications become more complex and our development teams grow, we will start to investigate different architectures, such as the onion architecture, which comes from domain driven design.

If you'd like to talk C# or have a requirement for an intelligent analysis tool, give us a call.

 

Back to Blog listings

ARGENTA IS A LEADING PROVIDER OF PRODUCT RELIABILITY AND PROCESS IMPROVEMENT SOLUTIONS.

Call 0121 514 2290 to discuss your requirements