By the time of writing this, the course was last updated on 16 Sep 2019. The original source code is in .Net 4.5 and uses NHibernate v4 for data persistence.
As part of my practice to better understand the topic. I followed the demos by rebuilding the source code with .Net 6 and EF Core instead of NHibernate.
EF Core Notes
Owned entities are essentially a part of the owner and cannot exist without it, they are conceptually similar to aggregates. This means that the owned entity is by definition on the dependent side of the relationship with the owner.
For dispatching domain event part. NHibernate supports event listeners for different events like
PostCommitInsertEventListeners. This is also can be managed in EF Core but in different ways, like:
It's not as straight forward as it's in NHibernate. But it achieved the same purpose. However I didn't include tests around this.
I implemented different solution structure than the original sample solution. My solution is structured as the following
- Domain project: For all domain entities with their business logic. It is
- Data project: For data access (DbContext & repositories implementations) & migrations (EF Core migrations) infrastructure.
- WpfClient project: For UI using WPF and MVVM.
- Domain.Tests project: For Domain unit tests using xUnit
I used Visual Studio 2022 with .Net6. Domain project is using
Running the solution
- Update connection string
- You need to set up the database first using EF Core
- Run the solution with WpfClient project as your startup project.
Connection string is hardcoded in:
To run database migrations. You need to have EF Core tools installed. Use this .Net CLI command.
Check If you have EF Core command-line tools:
Install EF Core command-line tools:
dotnet tool install --global dotnet-ef
Run Db Migrations for the solution:
dotnet ef database update --project src/DddInPractice.Data --startup-project src/DddInPractice.Data
Note that the above command assumes you are running the command from within the solution folder.
I highly recommend the course and the whole learning path if you are interested in the subject of Domain-Driven Design.
And if you are interested in the the updated source code you can find it here.