Dependencies6:01 with Alena Holligan
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.
You need to sign up for Treehouse in order to download course files.Sign up