First steps with DDDProject

DDDProject is an Open Source project whose purpose is to provide a DDD-style (Domain Driven Design) architecture to .Net developpers. Its goal is to ease developpement of maintenable, evolutive and robust apps, in a DDD spirit. Actually, the main part of the project is a sample application, which shows you a complete example of a forum application build on top of the DDDProject architecture. The sample uses DDDProject Aspects, which provides AOP facilities (This for example enables the management of Unit of Works in a very clear and concise way). Next part of DDDProject will be to bring some Visual Studio integration. This will enable developpers to :

  • Easily initialize a new solution based on DDDProject architecture.
  • Be more productive by automating some repetitive tasks during application development.
  • Be forced to follow DDD good practices during application development.

This will be done using Visual Studio Guidance Automation Toolkit.
Note : If you have good skills in GAT/GAX and are interested in participating to this open source project, you are welcomed. ;-)

DDDProject Architecture

The DDD-style architectural organization provided by DDDProject is built around 4 conceptual layers :

  • User Interfaces layer (Presentation layer) contains all the views end users can interact with. Here you can use whatever UI technology you want : ASP.Net Webforms, Winforms, ASP.Net MVC…
  • Application layer is a thin layer that coordinates business activities. Typically, this layer hold controllers components that ask domain entities to treat system events launched by end-users in the presentation layer.
  • Domain layer contains all the business logic of your application. It’s the heart of your system. The goal here is to have a true domain model (ie. Not a domain model composed of simple POCO entities with just some getters and setters). Here you should affect responsibilities to your domain entities and use real OO programming concepts, like polymorphism, encapsulation, inheritance, etc.
  • Infrastructure layer contains all infrastructure-related components ; i.e. Components that have technical goals (Repositories for data access, technical services for sending mail or talking to other system, etc.).

You can look at the sample app to have a full example of how you can build an application using this architecture, and to see how components are organized and how they communicate. The DDDProject architecture is built on top of lots of Open Source tools :

  • Castle Windsor IoC container to manage components (Repositories, Infrastructure Services, etc.).
  • NHibernate O/R Mapper at the infrastructure level, to allow Repositories components to interact with the database.
  • Castle NHibernate Integration Facility, Castle Transaction Service and Castle Automatic Transaction Management facility. Those tools are used to ease NHibernate usage and transaction management.
  • PostSharp Laos. Used by DDDProject Aspects to bring AOP facilities for managing Units Of Work or injecting infrastructure components into domain objects in a law coupled manner.

Note that the purpose is not to drown developpers under all of these tools. If you look at the sample app, you will see that source code is easy to understand and that these tools are architectural choices made to simplify developpers’ life. To be more concrete, developpers will never interact with Castle-related libraries, nor with PostSharp ones. They « just » have to learn playing with NHibernate (which has a steep learning curve, I admit…).

How to get and use the sample app

Below are the steps you must follow in order to download project’s sources (that include the sample application). Note that you will need Visual Studio 2008 and SQL Server 2005 (Express version is Ok) to play with the sample.

  1. You first need to install a client to access the Subversion repository that hosts DDDProject sources. Generally, we use TortoiseSVN. So go to TortoiseSVN download page : http://tortoisesvn.net/downloads, and install the software. Once the installation is complete, you should reboot your computer.
  2. Open an explorer and create a directory on your hard drive in which you will download the DDDProject source code. For example, creates the « C:\DDDProject\SRC\ » directory.
  3. Right-click on the created folder an select « SVN checkout » option. Under the « URL of repository » label, enter the address of the DDDProject Subversion repository : http://dddproject.googlecode.com/svn/trunk/, then click the OK button :

  4. Just wait a few moment while the sources being downloaded… When all is finished, you can go to the « C:\DDDProject\SRC\DDDProjectSample » folder, that should contains the sample application.
  5. Open Visual Studio 2008 and rebuild all the sample Solution.
  6. Last task will be to restore the databases. Go to the « C:\DDDProject\SRC\DDDProjectSample\BDD » folder : here are placed the backups you have to restore. Note that by the time you just have to restore « DDDProjectSample » backup. By default, the sample application is configured to use the « DDDProjectSample » database, under the local SQL Server Express instance. You can choose an other SQL Server instance to restore your database, but if so, you will need to change the config file « C:\DDDProject\SRC\DDDProjectSample\Config\NHibernate.config » (Just update the connectionstring property).
  7. Finally, hit F5 in Visual Studio to launch the app ! On the login page, use the following credentials : login : user1 / Password : a.

How to read the sample app

I’ve placed some long comments around the sample application code, in particular for the topic creation scenario. By Considering that you put your eyes on the right places, you should be able to quickly understand DDDProject philosophy. So I advise you to look at the following files, in the supplied order :

  • Application layer : Controllers/DomainController.txt
  • UI layer : NewTopic.aspx.cs
  • Application layer : Controllers/ForumController.cs
  • Domain layer : Forum.cs

Comments are not allowed on this blog. If you want to post comments, please use the dedicated discussion group here.