Factory Providers
Explain useFactory providers and when constructing a dependency requires logic beyond a simple class instantiation.
Most providers just map a token to a class Angular can instantiate directly, but sometimes constructing a dependency requires actual logic — reading a value from localStorage, choosing between two implementations based on a feature flag, or wrapping a third-party library's own initialization function. A useFactory provider handles exactly this case: instead of a class, you supply a function, and Angular calls that function (injecting whatever the factory itself needs via the deps array) to produce the value that gets registered against the token.
A useClass provider is like ordering a standard item off a menu; a useFactory provider is like giving the kitchen a custom recipe that combines several existing ingredients (deps) in a specific way before the dish is ready to serve.