Mapping Validation Attributes From Domain Entity to DTO

If you’re using something supporting DataAnnotations, you should be able to use a metadata class to contain your validation attributes: public class ProductMetadata { [NotEmpty, NotShorterThan10Characters, NotLongerThan100Characters] public string Name { get; set; } [NotLessThan0] public decimal Price { get; set;} } and add it in the MetadataTypeAttribute on both the domain entity & DTO: … Read more

What is the difference between Invariants and Validation Rules?

Absolutely, validation is the process of approving a given object state, while invariant enforcement happens before that state has even been reached. A corollary is that invariant enforcement is best performed by the thing that is being mutated (or created) itself, like a self-protection reflex, whereas validation is usually done by a third party. The … Read more

MVVM: Binding to Model while keeping Model in sync with a server version

In the past I ‘ve written an application that supports “live” editing of data objects from multiple locations: many instances of the app can edit the same object at the same time, and when someone pushes changes to the server everyone else gets notified and (in the simplest scenario) sees those changes immediately. Here’s a … Read more

What Belongs to the Aggregate Root

After doing even MORE research, I think I have the answer to my question. Paul Stovell had this slightly edited response to a similar question on the DDD messageboard. Substitute “Customer” for “Employee”, and “Order” for “Violation” and you get the idea. Just because Customer references Order doesn’t necessarily mean Order falls within the Customer … Read more

Nestjs Dependency Injection and DDD / Clean Architecture

Export a symbol or a string along with your interface with the same name export interface IService { get(): Promise<string> } export const IService = Symbol(“IService”); Now you can basically use IService as both the interface and the dependency token import { IService } from ‘../interfaces/service’; @Injectable() export class ServiceImplementation implements IService { // Used … Read more

Where to raise persistence-dependent domain events – service, repository, or UI?

My solution is that you raise events in both Domain layer and service layer. Your domain: public class Order { public void ChangeStatus(OrderStatus status) { // change status this.Status = status; DomainEvent.Raise(new OrderStatusChanged { OrderId = Id, Status = status }); } public void AddNote(string note) { // add note this.Notes.Add(note) DomainEvent.Raise(new NoteCreatedForOrder { OrderId … Read more

Event Sourcing and Read Model generation

Personally I think there’s nothing wrong with looking up the user’s name from within the event handler. But if you’re in a position where you can’t query the name from the User’s read model then I’d introduce an additional event handler to QuestionEventsHandler, to handle the UserRegistered event. That way the QuestionEventsHandler could maintain its … Read more

DDD Infrastructure services

Sticking with DDD definitions, a Repository is different than a Service. A Repository directly correlates to an Entity, often an Aggregate Root. A Service defines behaviors that don’t really belong to a single Entity in your domain. You can absolutely find Services in every layer, though the types of problems they address differ from layer … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)