In a healthcare SaaS platform handling 5M+ daily API calls, you run an ASP.NET Core service that processes patient scheduling, billing, and audit logging. The system must meet strict HIPAA compliance, and production incidents often trace back to subtle dependency injection (DI) misconfigurations: incorrect lifetimes causing memory leaks, accidental singleton state, and services resolving the wrong implementation in certain environments.
Explain how you handle dependency injection in an ASP.NET Core application.
In your answer, cover:
AddSingleton, AddScoped, AddTransient) and how ASP.NET Core resolves dependencies for controllers, middleware, hosted services, and background jobs.Assume the interviewer expects Staff-level depth: discuss container behavior under the hood, common pitfalls in high-throughput services, and practical patterns (options pattern, typed HTTP clients, factories) that keep dependencies explicit and safe.