Interview frequency: …
Short answer
Pass dependencies through a constructor or a composition root, so they can be swapped for a fake or another implementation without modifying the consumer.
Explanation
Injecting dependencies makes ownership and tests clear. Choose constructor injection in most cases, and use a container only when it actually reduces repeated wiring; fully hiding dependencies makes reading harder.
Code example
class UserPresenter {
UserPresenter(this.repository);
final UserRepository repository;
}Common mistakes
- Creating a dependency inside the class and then trying to mock it later.
- Passing a service locator into every method instead of a clear contract.