Prior to C# 10, you couldn’t use string interpolation (`$”…”`) in `const` declarations. Now you can, as long as all parts are also constants. Example Use Case Useful for defining attribute strings cleanly. Key Takeaways Components must be `const`; no runtime expressions allowed. Good for reducing magic strings.
Read more →Category: .NET
All .NET Related Stuffs goes here.
Testing .NET 6 Applications: Integration Testing with WebApplicationFactory
Unit tests are not enough. Integration tests verify your app works end-to-end, including middleware, dependency injection, and database logic. `WebApplicationFactory` spins up an in-memory test host. Setup Customizing Services Replace the real database with an in-memory one. Key Takeaways Use **Testcontainers** (covered earlier) for real SQL testing. Check HTTP status codes, response bodies, and headers.
Read more →Designing for Nullability in C#
With Nullable Reference Types (NRTs) enabled by default in .NET 6 templates, designing APIs that clearly communicate nullability is no longer optional—it’s expected. Enabling NRTs Guard Clauses Use the new .NET 6 helper to throw if null. Key Takeaways Use `string?` to explicitly mark nullable strings. Use `!` (null-forgiving operator) sparingly—only when you truly know […]
Read more →.NET 6: Minimal APIs Explained
Minimal APIs are the biggest shift in ASP.NET Core since version 1.0. They remove the MVC ceremony (Controllers, Actions, Filters) in favor of a fluent lambda-based syntax. The Code Is it just for tiny apps? No. Performance is technically better than MVC (fewer allocations, no Filter Pipeline overhead). However, organization becomes the challenge. You don’t […]
Read more →Building a GraphQL API with Hot Chocolate 11
Hot Chocolate is the premier GraphQL server for .NET. Version 11 brings “Zero Latency” execution engine improvements. Setup Projection The real power is in [UseProjection]. It translates nested GraphQL queries into optimized EF Core SQL queries (SELECT only what is requested).
Read more →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 →