> Symfony 7 >

Course Overview

Login to bookmark this course

Dependency Injection #[Attributes]

In modern Symfony, services can be configured using native PHP attributes, integrating configuration directly within the code. Let’s explore this with a practical example.

  • intermediate
  • 387 students
  • EN/ES Captions
  • EN/ES Script
  • Certificate of Completion

Your Guides

About this course

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": ">=8.2",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "symfony/console": "7.1.*", // v7.1.3
        "symfony/dotenv": "7.1.*", // v7.1.3
        "symfony/flex": "^2", // v2.4.6
        "symfony/framework-bundle": "7.1.*", // v7.1.3
        "symfony/mailer": "7.1.*", // v7.1.5
        "symfony/monolog-bundle": "^3.0", // v3.10.0
        "symfony/runtime": "7.1.*", // v7.1.1
        "symfony/string": "7.1.*", // v7.1.3
        "symfony/twig-bundle": "7.1.*", // v7.1.1
        "symfony/ux-icons": "^2.18", // v2.19.0
        "symfony/ux-twig-component": "^2.18", // v2.19.0
        "symfony/yaml": "7.1.*", // v7.1.1
        "twig/extra-bundle": "^2.12|^3.0", // v3.11.0
        "twig/string-extra": "^3.10", // v3.11.0
        "twig/twig": "^2.12|^3.0" // v3.11.0
    },
    "require-dev": {
        "symfony/debug-bundle": "7.1.*", // v7.1.1
        "symfony/stopwatch": "7.1.*", // v7.1.1
        "symfony/web-profiler-bundle": "7.1.*" // v7.1.3
    }
}

Traditionally, Symfony services were configured in XML or YAML files. This creates a bit of a disconnect between your code and the configuration. In modern Symfony, we can use native PHP attributes to configure services. This allows us to keep our service configuration right in our code as native PHP metadata, which is pretty cool! Let's dive into these Dependency Injection attributes in the context of a fun example.

Next courses in the Symfony 7: Learn More Tricks section of the Symfony 7 Track!

3 Comments

Sort By
Login or Register to join the conversation
Jared avatar Jared 3 months ago

Looking forward to this course! Thank you!

4 | Reply |
Braunstetter avatar Braunstetter 19 days ago

Thank you very much for this course. I love these courses that go beyond the fundamentals. And the new speaker is also great, although of course I miss Ryan.

| Reply |

Thanks for your feedback! That sounds like we are moving in the right direction.

Stay safe and happy coding! Cheers!

| Reply |

Delete comment?

Share this comment

astronaut with balloons in space

"Houston: no signs of life"
Start the conversation!