Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD, NHibernate, and Project Structure / Naming

What do you recommend as the proper project structure for a WebForms solution that is utilizing NHibernate and trying to bring in some DDD concepts?

Assuming the root namespace and solution name is Sample

  • Sample.Domain - contains my domain objects and my mapping files
  • Sample.Repositories - contains my repositories and nhibernate connection config file
  • Sample.Business - contains my business logic
  • Sample.Web - the actual WebForms project - all Presentation

What am I forgetting? Is there a more standard way to name these?
Any great blog posts on the topic?

like image 740
BuddyJoe Avatar asked Apr 13 '09 20:04

BuddyJoe


People also ask

What is DDD example?

An aggregate is a domain-driven design pattern. It's a cluster of domain objects (e.g. entity, value object), treated as one single unit. A car is a good example. It consists of wheels, lights and an engine.

What is DDD pattern?

DDD patterns help you understand the complexity in the domain. For the domain model for each Bounded Context, you identify and define the entities, value objects, and aggregates that model your domain. You build and refine a domain model that is contained within a boundary that defines your context.

Is domain-driven design still relevant?

Domain-driven design (DDD) is a useful approach that provides excellent guidelines for modeling and building systems, but it is a means to an end, not an end in itself. While the concepts are valid, you lose a lot if you limit yourself to using them only: There actually is a life beyond DDD.

What is domain in DDD principle?

Domain-Driven Design(DDD) is a collection of principles and patterns that help developers craft elegant object systems. Properly applied it can lead to software abstractions called domain models. These models encapsulate complex business logic, closing the gap between business reality and code.


3 Answers

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.

like image 194
Steven Lyons Avatar answered Oct 01 '22 18:10

Steven Lyons


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
like image 42
Jamie Ide Avatar answered Oct 01 '22 20:10

Jamie Ide


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.

like image 39
James Avery Avatar answered Oct 01 '22 19:10

James Avery