Domain Driven Design
Introduction to Domain Driven Design
Getting the software right is a hard thing to do. This is because business and developers do not always talk
the same language. Domain Driven Design is all about getting the language right between them.
- What is Domain Driven Design?
- Advantages of using Domain Driven Design
- When is Domain Driven Design a bad option?
- Anti-Pattern: Big Ball of Mud
- Anti-Pattern: Death by a Thousand Dots
Architecting Modern Web Applications
So what is a modern web application? One that uses Angular and TypeScript? With the speed that modern
web application developement evolves, there is the chance that your web site uses 'old' technology by
the time it is done. But sound architecture never goes stale. As a wise man once said: 'If you think good
architecture is expensive, try bad architecure'.
- "Clean" Architecture: put the business and application model at the center
- Understanding the Core, Infrastructure and Presentation layer
- Testing everything with Clean Architecture
- LAB: Build the application structure using Clean Architecture principles
Unit testing in .NET and .NET 5
Every developer want clean code that works. So how does one get to maintainable and working code? And
moreover: keep it working.
- What every developer wants: Quality code that works; and keeps on working
- Finding bugs: not just in code. - Or how NASA lost a 125.000.000$ Mars orbiter
- What is unit testing? And what is a good unit test?
- Understanding the difference between a unit test and an integration test
- Test Driven Development - Should you be doing it?
- Role-playing: Marge, Homer and Bart
- The Triple-A of unit testing - and what has cooking to do with this?
Unit testing with Visual Studio with MSTest and XUnit
When Unit Testing, you will have to decide on frameworks. There are several ones out there, which one do I need?
Visual Studio comes with a built in framework called MSTest, but you also have others, like the popular XUnit.
In this module, we will discuss pros and cons of these frameworks, and go into some best practices.
How do I know if I have tested enough? With code coverage you can see which paths in your code you have tested,
and easily discover untested conditional logic.
- MSUnit - Built-in into Visual Studio
- Building and running Unit Tests with MSUnit
- Using the Test Explorer Window
- Using Test Settings
- Live unit testing with Visual Studio
- Unit Testing best practices with XUnit
- Facts and Theories
- Unit testing parallelism
- Measuring and improving Code Coverage
When constructing the domain model, there are several approaches. Tactical Design provides a set of technical
resources that are used in the construction of the domain model. The goal is to enrich your domain model by applying
these standards correctly. When done so, it will reflect your business model with more clarity.
- What is tactical design?
- Entities, Services, Aggregates, etc...
- Applying Tactical Design to a real world business case
Tactical Design - Entities and Value Objects
DDD distinguishes between entities and value objects. How do you implement these?
- Differentiating between Entities and Value Objects
- Designing entities identity
- Designing immutable value objects
- Implementing Value Objects Equality efficiently
- C# 9 records
- LAB: Adding the Entities and ValueObjects to the game store
Tactical Design - Domain Services and Modules
Some behavior cannot be easily mapped to an existing entity or value object.
In this case we put this behavior into a domain service.
And how do we group our entities and such? Into modules.
- Providing domain specific operations with Services
- Segregating concepts using Modules
- LAB: Adding some domain services to the game store
One of the core pillars of DDD is Strategic Modeling. Strategic modelling helps you at
defining the Bounded Contexts, the Ubiquitous Language and Context Maps.
- The linguistic delimitation that are Bounded Contexts
- Identifying the terms and concepts with the Ubiquitous Language
- Relating Bounded Contexts with Context Maps
Tactical Design - Life Cycle, Aggregates, Factories and Repositories
Grouping your entities in Aggregates can make development easier, and help to avoid
the "Death by a Thousand Dots" anti-pattern. Entities have a life cycle, and how do
your create complex hierarchies of entities?
- Clustering Entities and Value Objects with Aggregates
- Abstracting the creation of Entities, Value Objects and Aggregates with Factories
- Data storage by using Repositories
- Abstracting queries using specifications
- LAB: Implemnting the life-cycle of your aggregates
Entity Framework Core
Introduction to Entity Framework Core
When a database is designed, the idea is to normalize data, i.e. avoid duplicate data. When designing the object
model for an application you try to come up with a design which is best suited for solving your business problems.
This means that mapping tables to classes one-on-one is often a bad idea. Entity Framework allows us to map the
relational world to the world of objects, allowing more complex mapping.
- What is Entity Framework Core?
- The need for Object Relational Mapping, especially with inheritance
- Decoupling conceptual data structure from logical data structure
- Querying data: APIs and LINQ
Entity Framework Core
With .NET 5 also comes a while new Entity Framework Core.
A new implementation of EF, which can run cross-platform, on Windows, Mac and Linux.
- Differences with .NET (Framework) 4.x Entity Framework
- Scaffolding your project from an existing database
- Understanding the generated code
- Interacting with the database with LINQ
- LAB: Scaffolding your model from an existing database
Modeling your database with EF Core
Mapping in EF Core uses conventions, attributes, or Fluent API.
You will see how to use these to model your database in EF Core and apply the changes
with Code-first Migrations.
- Methods of configuration
- Creating and applying migrations
- Table and column mapping
- Modeling properties
- Mapping Value generated properties
- Handling Concurrent updates
- Modeling relationships
- Mapping inheritance
- LAB: Mapping your entities to the database with EF Core
Advanced EF: Mapping DDD to EF Core.
Domain Driven Design is a great way to start designing your applications. Entity Framework Core is a
great framework to access and manipulate your data, stored in databases.
Now, how can we fit Domain Driven Design concepts into Entity Framework Core? Yes we can!
- DDD and Persistance Ignorance
- Implementing Value Objects with Owned Properties
- Using Shadow Properties to Avoid 'Leaky Abstractions'
- Building Repository and Specification classes
- Testing your Specifications
- Entity Validation
- LAB: Optimizing the mapping of your entities
Tactical Design - Domain Events
When building larger applications you want to keep low coupling and high cohesion.
So how do you implement changes that need to be handled by different sub-systems?
- What are domain events?
- Publishing significant domain changes with Domain Events
- LAB: Adding domain events to the game store application
Unit Testing ASP.NET Core Web Applications
When creating modern web applications with ASP.NET Core MVC, it's not that straightforward to
unit test the Controllers and Views. How does one validate wether the ActionResult returned
by the Controller action is the one you wanted, as well as whether the View is correct.
How do we replace dependencies during testing with MVC? How do we perform end-to-end testing?
- Challenges when unit testing MVC applications
- Writing unit test for your MVC controllers
- Unit testing your views
- Unit testing ApiControllers
- Using the ASP.NET Core testing framework
- End-to-end testing
- LAB: Implementing integration and end-to-end tests