DDD, NHibernate, and Project Structure / Naming

A few parts missing seem to be a central location for services needed throughout the solution and test projects. I usually have something like this:

  • Sample.Core - services and code that need to be used across the application
  • Sample.Data - domain classes and repository interfaces
  • Sample.Data.NHibernate - mapping files, fluent config, etc. and repository implementations, basically anything data mapping layer specific
  • Sample.Services - service implementations and interfaces
  • Sample.Web - web application

I have a matching tree of test projects:

  • Tests\Sample.Core.Tests
  • Tests\Sample.Data.NHibernate.Tests
  • etc...

Of course, the tree will get more complex depending on the project. As for discussions, check out the Onion Architecture. You can also check out the sample projects on Domain-Driven Design and see what you can take from those.


I have found everyone has their own preferences for naming, I prefer:

  • Sample.Domain - domain objects, mapping files
  • Sample.Services - business logic and services (and repositories, although I could see separating these out)
  • Sample.Web - Web Stuff.
  • Sample.Migrations - Data migrations.

Ben Scheirman also recently posted about this: Exporting Visual Studio Solutions with Solution Factory.

He uses a different structure but also includes a great way to standardize your template.


I keep it simple and lean towards segregating by namespace rather than by project, especially at the beginning. I usually start with three projects in the solution:

  • Sample - contains namespaces Sample.Model, Sample.Model.Mappings, and Sample.Services.
  • Sample.Tests - contains unit tests is structured the same as Sample.
  • Sample.Web - UI