Lyra
Learn
AI Learning Platform
π Midnight
π Comfort
π₯ Ember
π Paper
β Contrast
Exams
Sign in to track progress
β Back to the lesson
Module 3 Β· Quiz
DI Lifetime Scenarios
1. What is the primary reason for the issue of ObjectDisposedException in a singleton holding a DbContext?
The singleton is not properly disposed of after use.
The DbContext is scoped and its lifetime is longer than the singleton.
DbContext is designed to be used as a singleton.
The singleton captures a scoped DbContext that lives beyond its scope.
2. Which of the following correctly describes a scoped service?
It is created once per application lifetime.
It is created per request and disposed of at the end of the request.
It is created anew every time it is requested.
It is always thread-safe and does not hold state.
3. How can you correctly resolve a DbContext in a singleton service to avoid captive dependencies?
Create a singleton instance of DbContext and reuse it.
Inject the DbContext directly into the singleton service's constructor.
Use IServiceScopeFactory to create a scope and resolve DbContext within it.
Inject a transient DbContext into the singleton service.
4. Which scenario illustrates the concept of a captive dependency in Dependency Injection?
A singleton service using a transient service.
A transient service depending on a scoped service.
A singleton service depending directly on a scoped service.
A scoped service depending on a singleton service.
Submit answers
Continue: MVC, Minimal APIs, and Filters β
Review this lesson
Retake quiz