Which one to use
Transient
- since they are created every time they will use more memory & Resources and can have the negative impact on performance
- use this for the lightweight service with little or no state.
Scoped
- better option when you want to maintain state within a request.
Singleton
- memory leaks in these services will build up over time.
- also memory efficient as they are created once reused everywhere.
Use Singletons where you need to maintain application wide state. Application configuration or parameters, Logging Service, caching of data is some of the examples where you can use singletons.
Injecting service with different lifetimes into another
- Never inject Scoped & Transient services into Singleton service. ( This effectively converts the transient or scoped service into the singleton.)
- Never inject Transient services into scoped service ( This converts the transient service into the scoped. )