DEV Community

Discussion on: Adding Products to the Cart | Building a Shopping Cart with Symfony

Collapse
 
qferrer profile image
Quentin Ferrer

Hello. I use the autowiring of Symfony, so I don't need to manage service dependencies.

Autowiring allows you to manage services in the container with minimal configuration. It reads the type-hints on your constructor (or other methods) and automatically passes the correct services to each method.

To enable it, make sure that your config/services.yaml file configuration is like that:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
            - '../src/Tests/'
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mrgamingfrench profile image
SHINZO WO SASAGEYO

Of course !

How did I not think about that before ?

Been doing symfony for 4 years now and still forgetting basics lol .

Thx for the help. Much appreciated !