This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Let's take a look at how Slim uses a dependency container to prepare, manage, and inject application dependencies.
Dependency Injection Container
If we were packing a lunch and wanted to include an apple, our lunch box could specify an apple. Each time the lunch box is packed it would require an apple. In programming terms, this is call "tightly coupled" because our lunch box must contain an apple and cannot accept any other fruit. If we want to "decouple" the lunch box and the apple, we could instead "loosely couple" our lunch box with a fruit of ANY kind. The fruit available is contained in a refrigerator. This allows the one packing the lunch to add any available fruit to the lunch box. This is called "dependency injection". The fruit is a dependency of our lunch box, but the available fruit and the person packing the lunch control which fruit is injected into the lunch box. The person packaging the lunch is our application. The refrigerator is a dependency container and our fruit and our lunch box are objects working together to provide our lunch.
You can read more about Pimple, the dependency injection container used by Slim.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up