N-Layered ASP.NET Application: One class library for all my layers or one class library for each layer?
N-Layered ASP.NET Application: One class library for all my layers or one class library for each layer?
713 views Asked by Mazen Elkashef At
5
There are 5 answers
2
On
I prefer one class library for each layer. It provides good organization and hierachy between libraries. For example, UI layer never knows about Data Access Layer and it cannot know since it doesn't have reference to Data Access Layer.
However, sometimes layers are placed in the same class library to shorten the compilation time. If you don't have an overhead like this, always choose seperated one.
If your project is small enough that only one library suffices for each layer, then I would go with that approach. This helps to maintain a clear separation of concerns.
Separate DLLs will not adversly affect performance in my experience. There are some situations where it can assist performance (such as delay-loading rarely-used components). All the DLLs are loaded into the same address space, so as far as the runtime is concerned, one or many DLLs makes hardly any difference.
Each layer should be authored as though multiple front-ends are going to be using it. This will further help to maintain separation, and encourage code that is more correct and easier to maintain.