Monday, June 19, 2006

.NET 4 Beginners, How to structure a .NET 2.0 Solution

You have to design and implement a software app using .net 2.0 Visual Studio 2005, how do you structure the Projects in the Solution?

The basics

First of all you divide the solution in different projects, corresponding to the layers, modules, or components, defined in the design. Sometimes beginners tend to stack everything into one solution and then modularize the code by means of folders within the project, well, this is not the way to go.

The .net platform comes with the notion of projects, one solution has many projects, and projects can be of different types. For example Class Library Projects can be referenced by other projects, allowing modularization, encapsulation and reuse of code and functionality. Projects generate .exe, or .dll files, which are units of deployment, security and reuse.

Going one step further

Once you start dividing everything into a different project, the next thing that happens is, if the solution is big enough, that you start scrolling up and down to navigate a sea of projects, when you usually work with a couple of them at a time.
Visual Studio 2005 comes with this very useful feature which is to be able to add folders to one solution, grouping Projects and even folders in your own logical hierarchy. It's a simplification and an evolution of the former VS2k3 Enterprise Template concept. It's pretty handy.

Add folder to VS2005 solution
Now you can group projects following some criteria.

Define a good hierarchy

What is a good criteria to group projects? I'd say one that is intuitive enough for someone else to understand without asking too many questions, and that helps you do your job.
This point is particulary important when you need to standarize the way different groups work in a software factory.
You may be familiar with the following diagram, from the Microsoft's PAG group, from the "Designing Applications and Services"'s article.

I always liked this article, eventhough some say it's a bit outdated now, but it's good foundation and guidance.
Based on this article's guidelines about what are the layers and players in a three layered information system, you can choose to structure the solution aligned with it.

Besides that is good to separate the different concerns in the solution in with different folders, like: setup, testing, database..

The result of all that may look something like this:

Visual Studio 2005 .NET 2.0 C# Solution

1 comment:

fed_x said...

Nice article, i think it'll be very helpful for keeping the solution organized from the start.