Search for a command to run...

An order in most .NET codebases looks something like this:
Nothing here is wrong in the way a compiler would notice. It compiles, it runs, it ships. And then a customer places an order, the phone number field holds "call me after 5", the price is 0 because nobody set it, and the discount code is a string that means nothing until some service somewhere parses it. None of those are bugs in the code. They are bugs in the model: the types say almost nothing, so every rule lives somewhere else — in a validator, in a service, in a comment, or nowhere at all.
This is primitive obsession: modelling domain concepts with the language's built-in types. A price is a decimal. An email is a string. A phone number is a string. A currency is a string. The compiler cannot tell them apart, so it cannot help you. The fix is small and almost boring: give each concept its own type. That type is a value object.
A value object is a small immutable type whose identity is its value. Two Money instances with the same amount and currency are the same money. Two strings, "100" and "100", are also equal — but "100" the price and "100" the quantity are equal as strings too, and that is exactly the problem. A value object carries its own rules: it cannot be constructed in an invalid state, it compares by value, and it knows how to combine with its own kind.
In C#, the record type is the natural home for it. A record gives you value equality for free, immutability by default with get-only properties, and a syntax concise enough that the type stays smaller than the validation it replaces.
Take a price. In a store, a price is never just a number: it is an amount in a currency, and the currency is part of the value. Add 100 EGP to 50 USD and you have not computed a total — you have committed a category error that the compiler will happily approve if both are decimal.
Three things happened here that a decimal could never do. First, an invalid amount cannot exist: the constructor is private, and the only way in is Create, which rejects negative amounts and empty currencies. Second, the rules travel with the value: addition refuses to mix currencies, and the failure is a loud, immediate error instead of a wrong total discovered in a monthly report. Third, the type says what it is: a method that takes Money cannot be handed a quantity by accident.
Create throws on invalid input, and that is deliberate. An invalid Money is not an outcome the caller should handle — it is a programming error, caught at the moment of construction instead of three layers later at checkout. If your codebase already returns errors as values, Create can return a Result instead of throwing; the shape is a detail. The point is that invalid money cannot exist.
An email address is the classic case. As a string, "not-an-email" is a perfectly valid email right up until the mail server bounces it. As a value object, it is validated once, at construction, and every part of the system that holds an Email holds a valid one. There is no second validation step to forget.
Phone numbers are worse, because the rules are local. An Egyptian mobile number is 11 digits starting with 01, or +20 followed by 10 digits — and users type it half a dozen ways: with spaces, with a leading zero, with the country code, without it. Normalize once, inside the type, and the rest of the codebase never thinks about it again.
The normalization is the point. Every layer that used to strip spaces and compare prefixes — the checkout form, the SMS sender, the admin search — collapses into one place. If the rule changes, it changes in one file. And a phone number that was never valid cannot reach the SMS provider at all, because it could never be constructed.
The sharpest argument for value objects is not validation. It is argument order. A method that takes three strings will accept them in any order, and the compiler has no opinion:
That call compiles, ships, and sends the tracking number to the SMS provider as if it were a phone number. The failure shows up as a confused customer, not a build error. With value objects, the same mistake does not compile — the types are different, so the swap is caught where it was made, by the tool that is best at catching it.
The usual objection is the database. A value object is not a table, so how do you store it? EF Core has two answers, and both are a few lines in the configuration:
The columns stay a decimal and a string. The domain never sees the primitive again; the database never sees the object. The mapping lives in one configuration class, and nothing else in the codebase knows or cares. One honest side effect: a corrupt row in the database now fails loudly at read time, when EF Core tries to construct the value object, instead of travelling silently through the system as a bad string.
Not every string deserves a type. A value object earns its place when a concept has rules, and it is ceremony when it does not:
Free-form text with no rules — a note, a description, a comment. A string is the honest type for text nobody validates.
A concept used in exactly one place with one rule. A value object with a single check is ceremony; wait until the second use, then extract it.
A hot path allocating millions of values per second. A record class allocates on the heap; if profiling proves it matters, use a readonly record struct, which keeps the rules and drops the allocation.
The test is simple: if two places in the code would independently validate the same string, it is a value object waiting to happen. If only one place cares, leave it alone.
Start at the boundary: the checkout endpoint, the place where bad data enters. Parse strings into value objects there, and let the rest of the system deal in Money and Email instead of decimal and string. The primitives disappear one method at a time, and the code that still uses them keeps working — a value object wraps a primitive, so the conversion is always one line away. A codebase does not need a big-bang refactor; it needs one type that proves the idea. Then the next developer who is about to write a validation method in a service will reach for the type instead.
A string can hold anything, which is another way of saying it means nothing. Give the concepts in your domain their own types, and the compiler starts enforcing the rules you used to write in comments.
Primitive obsession is not a dramatic bug. It is a slow leak: validation copied into three services, a swapped argument that compiles, a price in the wrong currency that only surfaces in the monthly report. Value objects plug the leak at the source, one small type at a time. Start with Money. Your checkout will thank you.
A list of orders in memory, rows streaming out of a database, pages from an API - from the consumer's side they are the same question: give me the next item, and tell me when there are no more. The Iterator pattern is that question answered as an interface pair, and in .NET it is the shape of foreach and LINQ themselves: hand-built enumerators, yield return, deferred execution, and the async twin IAsyncEnumerable<T> - including the costs, and when a List is the honest answer.
An order is placed, and five parts of the system need to know. The Observer pattern flips who knows about whom: the publisher announces one fact, subscribers come and go, and the publisher never changes. From hand-built subjects to C# events, IObservable<T>, and MediatR notifications - with the push and pull models demonstrated in code - including the costs, and when a direct call is the honest answer.
A price is not a decimal, a phone number is not a string, and an email is not a string either. Primitive obsession is the habit of modelling domain concepts with the language's built-in types — and value objects are the small, boring, enormously effective fix.