Dependency Injection in .NET: Service Lifetimes

Choosing the right lifetime for your services is critical for app correctness and memory usage. Transient Created every time it is requested. Lightweight, stateless services. Scoped Created once per HTTP request. Ideal for DB contexts, user session data. Don’t inject Scoped into Singleton! Singleton Created once per application lifetime. Examples: Caching services, configuration. MUST be […]

Read more โ†’

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

Entity Framework Core 5.0 ships alongside .NET 5 and brings features that developers have missed since EF6. It completes the “missing features” gap while pushing performance further. Many-to-Many Relationships Finally! You no longer need to manually map the join table entity. EF Core 5 creates it for you automatically. Split Queries A common performance pitfall […]

Read more โ†’
Posted in UncategorizedTagged

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

Metaprogramming in C# has historically relied on reflection (slow at runtime) or T4 templates (clunky build integration). C# 9 changes the game with Source Generators. They allow you to hook into the compilation process, inspect your code, and generate new C# files on the fly that get compiled with your project. How It Works Example: […]

Read more โ†’