Search code examples
.netasp.net-mvcasp.net-mvc-4n-tier-architecture

Why n tier is different in .NET compared to other languages


All projects that I have done had the ui layer and domain data access layer. And for example ruby projects store data access in model project folder. Asp mvc have the same mvc structure like ruby but we still use separate assembly for data access and model for view models.

Why is that? Why .net developers always create separate assembly for dal is it wrong to put dal in model folder of the project?


Solution

  • One possible reason is that the ui layer needs knowledge of the model but not the details of how to retrieve the model from the database server. The database access layer would certainly need to have knowledge of the model. So you need a means to share this knowledge across the two or more physical (n-tier) layers.

    The easiest way to do this is to have the model in a separate assembly. The ui layer can have a reference to the model assembly and the data access layer can also have a reference to the model assembly.

    The benefit of this is that when you come to deploy the app if it's deployed across different physical layers then you can deploy just the assemblies you need. If the model were part of the dal assembly or vice versa then you would be deploying db code to the ui server where it has no purpose.

    There are many deployment architectures to choose from each has their benefits and drawbacks consequently there is no one correct way to do it: it depends. A separate model simplifies the process of sharing a model across several tiers which in turn may be separate projects within the same solution

    So you don't always have to put the model in a different assembly however it's convenient, helps reduce code complexity and generally good practise.