Chapter 3 – Dependency Injection
- There are four types of dependency injections (DIs): constructor, method, property, and view injections. The constructor injection is the most commonly used approach for building ASP.NET Core applications.
- There are three types of DI lifetimes: transient, scoped, and singleton.
Use a transient lifetime when you are unsure about how you should register the service. This is the safest option to use, and it's probably the most commonly used because services are created each time they are requested. This lifetime works best for lightweight and stateless services because they are disposed at the end of the request. Be aware, though, that a transient lifetime can potentially impact the performance of your application, especially if you are working on a huge monolith application, where the dependency reference is massive and complex.
Use a scoped lifetime when you want an object to be created once per client web request. This is to ensure...