Symfony 3: Level up with Services and the Container

This page is archived

We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.

Alternate resources

Now it's time to level up with services. These special PHP objects are the backbone of what makes Symfony unique and fast. It's also the reason that organizing your code into reusable chunks is so easy. But beyond that, once you understand how services and the service container work, you'll be absolutely unstoppable inside of Symfony. This series, from our friends at KnpUniversity covers:

  • What is a service?
  • List, fetch, and use existing services
  • Create your own custom services
  • Register your service
  • Check out the (mystical) dumped container
  • Configuration Parameters
  • Dependency Injection Tags

If you haven't already, check out Joyful Development with Symfony and Symfony 3 Fundamentals: Bundles, Configuration and Environments to get caught up with Symfony 3 fundamentals.

Tutorials in this course
More information

In this lesson, we'll explore what problems a services architecture can solve. You'll learn how services can unlock a bunch of powerful features for you in Symfony 3.

New to Symfony 3 or need a brush up on Symfony concepts? Check out these series first and then head back here to dive into Services and the Container.

Note: To set up the project and code along, see the instructions in start/README.md.

More information

In this lesson, we'll move code out of the Controller and into a new class. You'll learn how to create this new service class and refactor the code that you took out of the Controller to work in this new context.

More information

In this lesson, you'll learn about the dependency injection workflow and refactor our code to inject the dependency.

More information

In this lesson you'll learn how use type-hinting to make your code more portable—and readable, too.

More information

In this lesson, you'll learn how to register your service in the container so that you can can access it in your class.

More information

In this lesson you'll inject cache service, applying what we've already learned about dependency injection and type-hinting as we refactor the code in our evolving app.

More information

In this lesson, you'll learn how to extend Twig and create a Twig extension service to use in our Symfony 3 app.

More information

In this lesson, we'll add tags to our services YAML file so that Twig knows about our new Twig extension. We'll discuss the reason behind tags and refactor our service with our new understanding of dependency injection tags!

More information

In this lesson you'll learn what happens when you set autowire to true when you register your service.