N-Layered ASP.NET Application: One class library for all my layers or one class library for each layer?
-
@IKashef does this question is applicable to enterprise web applications like www.bantamlive.com – Harsh Baid Mar 04 '11 at 16:24
5 Answers
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.

- 58,241
- 9
- 71
- 99
-
I didn't understand this one comment "Your question must not have been "self-explanatory". :-)" :D .. but your comments and answers made it so clear .. Thank you (Y) – Mazen Elkashef Mar 04 '11 at 01:21
I would go for class library for each layer. This way you could reuse you libraries in other projects. Also this will give you more flexibility...

- 10,193
- 12
- 57
- 79
-
but having more than library and forcing the application to go through different DLLS does this affect my application's performance or not ? – Mazen Elkashef Mar 03 '11 at 20:33
-
@lKashef - Your question must not have been "self-explanatory". :-) – Jeffrey L Whitledge Mar 03 '11 at 20:37
-
@lKashef I don't think that having many DLL will some how effects your's application performance. – Darius Kucinskas Mar 03 '11 at 20:38
-
It does impact performance.. However, it could be a positive or negative impact. Regardless, its really only during the initial load this matters; and it's usually very minor. – NotMe Mar 03 '11 at 21:23
why not use both, one common class library for all global stuff and one class library for each of the projects for project specific things
of course we need to know more about your particular situation to be more accurate, there is no one-case-fits all solution unfortunately

- 10,476
- 1
- 24
- 35
-
@K Ivanov. It's kind of a CMS so it's pretty simple, I add stuff from the back-end and show them on the front end, I let visitors add items and validate them, then add them to the database. and of course from the back-end you can see administrator all the website's content (edit, delete and search) – Mazen Elkashef Mar 03 '11 at 20:35
-
there are many pasterns that can be use and all have their pros and cons, best to do some reading and select something simple and expendable, here some ref to start you with http://en.wikipedia.org/wiki/Multitier_architecture – Kris Ivanov Mar 03 '11 at 20:39
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.

- 3,910
- 9
- 39
- 64
-
@Ahmed. I'm sorry, are you trying to say that if I have a lot of traffic on my website, then separate layers will cause longer compilation time and hence, performance issues !! – Mazen Elkashef Mar 03 '11 at 20:38
-
1@lKashef - The program is not compiled separately for each user. IIS will maintain a compiled version of the application until it is stoped or the code is modified. This has nothing to do with how much traffic you have. Also, separate DLLs improves compile time, because only projects that have changes need to be recompiled. Breaking a solution into two output binaries could potentially cut the compile time in half. – Jeffrey L Whitledge Mar 03 '11 at 20:46