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!