Demonstrations, Tests, and Examples of Dependency Injection Lifetimes in .NET
Want to learn about transient, scoped, and singleton lifetimes? Start here.
Simple tests demonstrating transient, scoped, and singleton lifetimes. If you are new to dependency injection lifetimes, these tests provide simple use cases to build an understanding.
A list of best practices including
- When to use AddDbContext vs AddDbContextPool
- How to properly use HttpClient
- How to use scopes within services
A console application that runs a job every five seconds. This example demonstrates how to use scopes to properly handle Entity Framework's DbContext and other dependencies where lifetime consideration is important.
A Quartz.NET IJobFactory that creates a lifetime scope for each job.