C# 12 primary constructors can significantly reduce boilerplate in DI service classes by eliminating field declarations, constructor bodies, and assignments. The author shares their experience switching to primary constructors for ASP.NET Core services, explaining the key pitfall: parameters are captured as mutable variables,

6m read timeFrom milanjovanovic.tech
Post cover image
Table of contents
What Changed My MindWhere I Use Them Most: DI Service ClassesEntity Construction (With a Caveat)The Pitfall That Almost Stopped MeWhere I Still Use Traditional ConstructorsSummary
3 Comments

Sort: