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

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 ...

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