Thursday, 4 December 2008

Visual Studio Solution Structure

I've been playing about with Visual Studio 2008 and the new features of c#3 on and off for a couple of weeks and lining up to get a couple of small projects up and running. One of them is my own website, one is a survey for next season for TDs and participants in national tour events.

I wanted to get the solution construction right for my website solution so that I can add a lot of stuff in over time and not have to re-work it to fit more things in. After setting up a subversion source control server for personal usage I decided that this was the time to mess about and I can always roll back bits if something goes wrong.

I wanted to keep the structure so that it was separated and also unit testable (yes I'm a unit test geek). This lead to having separate projects in the solution into different areas ... Data access, Model classes, Services and UI (using Solution folders works wonders for this ... more later).

*Top tip* To get your namespaces as you'd like them start by naming the projects as you'd like the namespaces to be. A good starting point is . as all the files in the projects will start with that namespace as standard unless you change them.

The data access project is self explanatory. I've decided to start using/playing with the Microsoft Entity Framework for this. I'm still learning how the EF works and best practices and I'm sure I'm still not using this properly but ah well; we live and learn! I've been reading about the Linq2Sql vs EF madness which has been going on over the past month since PDC, but I don't think it'll affect a little single "out of hours" home coder.

The model project is where all the domain model classes go. I'm still trying to work out how this goes with the EF in the data project so if any one can point out how these should operate together *properly* then some pointers would be much appreciated.

The service project is there for a wcf service project. I've put this in place so that I can access the data asynchronously via javascript in the future for an ajax look and feel with responsive UI and to avoid unnecessary postbacks.

UI is made up of a couple project types. The main one is a MS MVC project template which will serve as the main "website" in a traditional sense. It is made up of pages or views which will display different images / inputs / data and will also serve as host pages for the second UI project type; a silverlight 2 project. I've added this in as I want to start playing about with silverlight, and the eventual plan is to do my own site in both postback/views way, responsive UI javascript/async calls way and to have a RIA with silverlight.

To enable the solution to be grouped into logical I have used Solution folders to group the project and associated test project together. Solution folders are not related to the file structure they are purely there for organisational purposes. They also have more functions which can be found my reading the above link.

In addition to the grouped projects I have also added in a separate class projects for extension methods and global definitions. These projects will be referenced by one or more projects and will not reference any other project (as circular references are bad!).

Another tip I would use if you are going to go down the Unit test route would be add a file structure folder in a logical place in the solution and add in your mocking / helper dlls in this folder. You can then add in single references into each unit test project to one set of dlls. If you are putting your code into a source control system then add them into your solution and file them away into a "External" solution folder so that you can hide them away but still have them "under control".

Well this is the structure I am going to work with for a while and see how it gets on. You have any thoughts on the matter or pointers to improve this structure then please let me know.

This is the first post I've done of a technical nature so any comments about that would also be appreciated :-)

No comments: