Tutorial: Refactoring an ASP.NET Controller with Stopwatch and Primary Constructors
A hands-on tutorial for ASP.NET developers walks through fixing a basic ASP.NET app built with .NET 10 and C#. The guide focuses on cleaning up a controller by removing redundant methods and replacing DateTime with Stopwatch for more accurate response-time measurement. It also explains how primary constructors in C# implicitly turn injected services into class fields, which can cause lifecycle issues. Specifically, if a Singleton class depends on a Scoped service, that Scoped service will live as long as the Singleton, potentially causing bugs. The series plans to cover Entity Framework Core in an upcoming installment.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in