Contract Generation

Maintaining hundreds of Event (and Command) contracts manually is both tedious and error prone. It’s usually more efficient to express their definitions in some compact domain-specific language (DSL) that can be used for simple code generation, by building correct classes at build time. There are several ways to formulate a DSL syntax, and we might consider the Protocol Buffer .proto format or a similar one to be the way to go. For example, you may find this approach useful:

CustomerInvoiceWritten!(InvoiceId Id, InvoiceHeader header,    InvoiceLine[] lines, InvoiceFooter footer)

A simple code generator can use the parsed DSL to generate code for each source line. Note one example here, where ...

Get Implementing Domain-Driven Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.