Dependency injection means a class receives what it needs instead of creating it: public class InvoiceService(IMailer mailer) rather than new SmtpMailer() inside. Tests pass a fake, and production code gets the real thing from a container: you register services at startup (builder.Services.AddScoped<IOrderRepo, SqlOrderRepo>()) and the container builds each class, filling its constructor parameters.
Every registration has a lifetime. A singleton is created once for the whole app (caches, clocks, settings). A scoped service is created once per request, or per scope you create (a database context, a unit of work). A transient service is new every time it is asked for (small, stateless helpers).
The classic mistake is a captive dependency: a singleton that takes a scoped service in its constructor keeps one instance forever. The container refuses it ("Cannot consume scoped service ... from singleton ..."); the fix is to inject IServiceScopeFactory and create a scope per unit of work.
About the code here: The real container package does not run in this browser runtime, so these exercises use a small stand-in for Microsoft.Extensions.DependencyInjection, with the same names and the same rules for what this lesson checks. It is a simplification: no keyed services, no open generic registrations, and no list of every implementation of an interface.
Registrations with the three lifetimes, and a service resolved from a scope.