A small example
Suppose an invoice service sends a receipt by calling a specific email library directly inside its code. To test the invoice logic you would send real emails. With injection, the service asks for "something that can send a message" in its constructor. Production passes the real email sender; a test passes a fake that records the call.
What you gain
- Testing: swap real services for fakes without touching the code under test.
- Flexibility: moving from one SMS provider to another changes one wiring spot, not fifty files.
- Clarity: a constructor lists everything a class needs, which exposes classes that depend on too much.
Containers and their limits
Frameworks such as Spring, ASP.NET Core, NestJS and Laravel include a container that builds and connects these objects. You do not need one to use the idea; passing arguments by hand is also injection. Overusing a container can hide where objects come from, so keep wiring in one obvious place.
Questions, answered
No. Even a small script benefits when it can accept a fake database in a test.
Dependency injection is one common way to achieve inversion of control, where the framework or caller decides what gets used.