Skip to main content

Posts

Showing posts with the label DDD

DDD–Strongly typed Ids-Using C#9 Record Types

I blogged before about the usage of Strongly typed Ids in your domain models. With the introduction of C#9 record types, an alternative approach becomes an option. Record types are reference types with built-in immutability and value semantics. They automatically provide implementations for Equals , GetHashCode , etc, and offer a very concise syntax known as positional records . This allows us to rewrite our ProductId type using records: public record ProductId(int Value); That’s all that is needed. Thank you C# 9!

DDD–Strongly typed Ids

One of the core principles of DDD is the usage of value objects to avoid “primitive obsession”. "Primitives" refer to the built-in types in C#,  int , string,guid etc. "Primitive obsession" refers to over-using these types to represent domain concepts that aren't a perfect fit. Some examples are a HouseNumber that is represented by an int or an EmailAddress that is represented by a string. This concept not only makes sense for your value objects but is also valuable for your Entity and AggregateRoot id’s. A ProductId should not be interchangeable with an OrderId. Creating a valueobject for every Id type is not that hard but remains cumbersome. Let’s introduce StronglyTypedId as a solution. From the website : StronglyTypedId makes creating strongly-typed IDs as easy as adding an attribute! No more accidentally passing arguments in the wrong order to methods - StronglyTypedId uses Roslyn-powered build-time code generation to generate the boilerplate ...

Transport Tycoon exercises for DDD

While searching something on Github I stumbled over the following repo: https://github.com/Softwarepark/exercises/blob/master/transport-tycoon.md This is a set of Domain-Driven Design (DDD) exercises. They take place in the universe of the Transport Tycoon . It is a game "in which the player acts as an entrepreneur in control of a transport company, and can compete against rival companies to make as much profit as possible by transporting passengers and various goods by road, rail, sea and air." If you want to learn about DDD, or practice your DDD skills this is a great way to start…

Event Storming Cheat sheet

If you want to organize your own Event Storming workshop, here is a good cheat sheet to get started with: https://github.com/wwerner/event-storming-cheatsheet This cheat sheet aims to provide a short opinionated summary of preparing and facilitating an Event Storming Workshop. It is not intended to give a complete introduction to the topic, prior knowledge on DDD and Event Storming is required to make responsible use of this document.

ValueTuple magic for Equality checks

Until we have record types in C# we’ll have to use classes or structs for our Value objects. What makes this annoying is that we have to override the Equals and GetHashCode methods to get correct equality checks. Until I stumbled over the following blog post by James Montemagno: https://montemagno.com/optimizing-c-struct-equality-with-iequatable/ . In this post he explains how we can use ValueTuples in combination with the new tuple syntax to get cleaner Equals and GetHashCode checks. Here is the code before: Here is the code after introducing ValueTuples:

Rearchitect a monolithic .NET application using microservices

Google goes “all-in” to win the hearth and mind of .NET developers to let them use the Google Cloud Platform. To support this effort they released a set of whitepapers to help you rearchitect your monolithic .NET application using microservices and modernize your authentication, database and caching building blocks. Here are the whitepapers: Move-and-improve white paper about rearchitecting a monolithic .NET application using microservices Modernizing your .NET Application for Google Cloud white paper about modernization of critical functions, including authentication, database and caching   All improvement steps are done on a typical .NET application. You can find the related code in this GitHub repository .