O'Reilly logo

Implementing Domain-Driven Design by Vaughn Vernon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Event Immutability

Event Streams are considered to be immutable by nature. In order to keep the development model consistent with this concept (and avoid undesirable side effects), Event contracts should be implemented as immutable. To do that with C# on .NET, we mark fields as read-only and set values only via the constructor. Given the previous ProjectClosed Event, we can make it an immutable implementation:

[DataContract] public class ProjectClosed {   [DataMember(Order=1)] public long ProjectId { get; private set }   [DataMember(Order=2)] public DateTime ClosedUtc { get; private set; }   public ProjectClosed(long projectId, DateTime closedUtc)   {     ProjectId  = projectId;     ClosedUtc = closedUtc;   } } ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required