Search code examples
c#namespacesprojects

Namespace within a project or separate project


I'm trying to read about best practices in C# development. I came across people creating different class library projects within a solution. I have been developing solutions for C# but never create separate projects for my classes. Though, some of my projects were small. To separate my namespaces, I normally create folders. Are there any good reason why I should create a separate project for my class modules?


Solution

  • Reason to create a separate project:

    When we create a project of type Class Library, after the build the MSbuild process spits out an assembly/ dynamic linked library or .DLL file. This .dll file can be referenced in any project in the same or other solution. This supports the code reusability.

    A general rule of thumb for a web based (ASP.Net MVC) solution structure is given as below:

    1. Create a Domain Model project (Class Library project type)
    2. Create a Data Access Layer (Class Library project type)
    3. Create a Service Layer project (Class Library project type)
    4. Create a UI Layer project (ASP.Net MVC project type)

    Create the unit test projects (Class Library project type) for each project listed above.

    Hope this helps.