Search code examples
c#organization

What is the optimal way of organizing a C# project?


I was wondering here, how do you guys organize your projects, in terms of functionality, scope, etc.

Do you have one project for unit tests, one project for class library code, one project for User Interface?

Or do you just divide all these into separate folders?

I was thinking that separating these by projects is easier, because your central code library is at one place, without direct references to the UserInterface (no WinForms dependencies) or the UnitTests.

Any opinions?


Solution

  • I try to divide projects into what you might call "deployment units." In other words, "How might I deploy these assemblies?"

    Because I'm obviously not deploying unit tests, they are in their own project.

    I then divide UI and "business logic" into separate projects. If I keep those lines of separation clean, I can replace my UI layer with a new technology or infrastructure (think WPF vs. ASP.NET) and still reuse the "business logic" assemblies for both. I just introduce a new UI layer that understands the business logic interface.

    I also try to keep a separate library for code that I might share between solutions. This would be my data access utilities, file parsing utilities, and others that I use over and over as I build projects. I can just include those assemblies into my new solutions and I get all of that functionality that I've already invested my time in.

    Hope that helps.