C# 12 Primary Constructors: Less Boilerplate, Same Responsibility to Store State
C# 12 allows primary constructors on classes and structs, not only records. They put constructor parameters in the type declaration and make those parameters available throughout the type body. For small services and immutable value-oriented classes, this can remove repetitive constructor code.
For example, a service can declare its invoice store and logger in the class signature, then use those parameters in its methods. The syntax removes the explicit constructor and field assignments, but it does not make those parameters public properties.
The subtle point is that primary-constructor parameters are still parameters. They are not automatically public properties, and the compiler may only capture them when members use them. If a parameter is assigned or referenced from several members, the compiler can synthesize storage. That makes the compact syntax useful, but the object’s state is less visible at a glance.
Use it when the type is small and the dependencies are unambiguous. Keep explicit fields or properties when they clarify lifetime, mutability, validation, or public API. Avoid turning a long constructor parameter list into a long type declaration; that is still a design signal that responsibilities may need separating.
The most reliable review question is: could a teammate understand what state this object retains by reading the declaration and its members? If not, a conventional constructor with explicit fields may be clearer. Concision is a tool, not a style requirement.
Primary constructors are one of several C# 12 features, alongside collection expressions and other improvements. Read Microsoft’s C# 12 feature guide and primary constructors tutorial before applying the syntax across a codebase.