I'm trying to get to grips with Domain Driven Design and MediatR. A reaction to being involved with applications that favour Services for almost everything. I see so much value in DDD and I'm trying to increase my understanding to write better more maintainable software. For software context I'm using a .netcore Razor Pages application (trying to use Clean Architecture layout). For business context I'm dealing with Memorials and ServicePersons. Memorials have RecordedNames (link table with additional properties). Memorial -> RecordedNames <-ServicePerson
The thing I'm trying to work out is where best the validations and business rules ought to go.
There's the 2 types of validation I have in mind:
- Request validation - e.g. An email field is [required] and is it a [valid email address].
- Business rules - shouldn't add the same person to the same List.
Request Validation
Initial thoughts are: Options:
- PageModel properties/ViewModel - Similar to each other
- MediatR Pipeline -Pre with Fluent Validation.
One of the nice things about using PageModel properties with attributes validation is it gives the client side unobtrusive out the box too. But it's at the expense of writing mapping code for each operation like this into the PageModel class properties.
Whereas when I consider using MediatR pipeline to do Request Validation, I would need to handle that all separately and more manually.
Business Rules
E.g. We shouldn't add the same person to the same memorial more than once.
- Have them in the Domain of Aggregates/entities/ValueObjects - MediatR just acts as a handler between the UI and the Domain object.
- Use MediatR Command and have the business logic there. However this feels like it starts to fragment the Domain business rules, but looks like the norm with MediatR. With that in mind I then start to wonder about the value of adding MediatR in, so as much as anything I'm trying to understand MediatR's strengths too.
Thoughts so far
Lastly
A colleague is pushing for the Aggregate Domain Objects to be used in the PageModel, which just feels all kinds of wrong.