Dependency Injection in .NET: Service Lifetimes

Using the wrong DI lifetime is the #1 cause of concurrency bugs in ASP.NET Core. We revisit Singleton, Scoped, and Transient with a focus on thread safety. The Three Lifetimes Lifetime Created… Thread Safety Transient Every time requested Safe (Instance per usage) Scoped Once per HTTP Request Safe (Single thread per request) Singleton Once per […]

Read more โ†’

C# 9.0 Top-Level Programs: Reducing Boilerplate

C# has always been criticized for the “Hello World” ceremony. You needed a namespace, a class, and a static Main method just to print one line. C# 9 Top-Level Programs remove this requirement, bringing C# closer to scripting languages like Python for simple tasks and microservices. The New Entry Point Behind the Scenes The compiler […]

Read more โ†’

Entity Framework Core 5.0: Many-to-Many and More

EF Core 5.0 brings the feature everyone has been asking for: Many-to-Many relationships without a mapped join entity. It also introduces Split Queries to fix the “Cartesian Explosion” problem in complex joins. Many-to-Many You can now define navigation properties on both sides, and EF Core handles the middle table. Split Queries Instead of one giant […]

Read more โ†’

Source Generators in C# 9: Compile-Time Code Generation

Source Generators allow you to inspect code during compilation and generate new C# files on the fly. Unlike Reflection (runtime slow) or IL Weaving (complex), Source Generators are fast, debuggable, and integrated into Roslyn. How it Works Example: INotifyPropertyChanged Automate the boilerplate of MVVM. Key Takeaways Generators can **add** code, but cannot **modify** existing code. […]

Read more โ†’