Attendance App: Real-Time Use of DI Lifetimes
Dependency Injection (DI) in ASP.NET Core is more than just a design pattern — it’s a powerful tool for managing service lifetimes and dependencies in real-world applications. In this guide, we'll explore how an Attendance App uses different DI lifetimes (Singleton, Scoped, Transient) to handle services like logging, attendance tracking, OTP generation, and email notifications. ๐ฏ App Features Students check-in/out Admins manage students Operations are logged (Singleton) Attendance tracked per request (Scoped) Email/OTP as lightweight utilities (Transient) ๐ Quick Overview: DI Lifetimes in ASP.NET Core Before diving into the app, here’s a quick refresher on DI lifetimes: Singleton : One instance shared across the entire application lifetime. Good for stateless or shared resources (e.g., logging). Scoped : One instance per client request. Ideal for services that maintain request-specific state or database transactions . ...