HomeInterview QuestionsIs dependency injection related to passing functio…

Is dependency injection related to passing functions?

🟡 Medium Conceptual Junior level
1Times asked
Apr 2026Last seen
Apr 2026First seen

💡 Model Answer

Yes, dependency injection can involve passing functions as dependencies. In many languages, functions are first‑class values, so you can inject behavior by supplying a function reference instead of a concrete class. This is a lightweight form of DI, often called "functional dependency injection." For example, a logger might be injected as a function that accepts a message string. While traditional DI frameworks focus on injecting objects or services, passing functions extends the concept to behavioral injection, allowing callers to customize logic without modifying the dependent class. However, DI is broader: it can inject entire object graphs, configuration data, or interfaces. Function passing is just one technique within the DI toolbox, useful when the dependency is purely behavioral and stateless.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500