In this episode, we walk through how to use services inside controllers in our application. Instead of hard-coding values like your app's name directly into your homepage, you'll see how to leverage your container's setup—to fetch configuration details and use them wherever you need.
We revisit the container and see how services (like our config provider) are registered and made accessible. Using constructor dependency injection and the power of auto-wiring, we demonstrate how you can pull dependencies, like config, into your controller. From there, it becomes super easy to output your app name (or any other value from your config) right onto the homepage.
By the end of the episode, you'll understand why this method works: when the router resolves a controller via the container, it automatically wires in constructor dependencies. This makes everything clean, reusable, and testable. Plus, as your app grows, you'll see how you can add more services, like a view renderer, by pulling them into constructors in the same way.
In short, you learn how to access anything you need from the container inside your controllers, making them a lot more powerful and flexible!