dunglas / DunglasActionBundle

Symfony controllers, redesigned
https://dunglas.fr/2016/01/dunglasactionbundle-symfony-controllers-redesigned/
MIT License
256 stars 14 forks source link

A way to avoid autowiring in specific classes #71

Open magarzon opened 7 years ago

magarzon commented 7 years ago

Hi.

One feature that I miss is the ability to exclude some classes of the autowiring, when a directory is added in the configuration.

Often I find that I have a bunch of related services that I want them to be autowired, but among this services there are utility classes that are not services, but that have a constructor and/or setters, and that they are in the same directory (as they are related, they are part of the same feature).

At the end I have to configure them in the services.yml or move this utility classes to another directory.

Probably this feature could be implemented with an annotation, or an exclude path/regex in the configuration...

bpolaszek commented 7 years ago

+1 - It's a common practice to have value objects into sub-namespaces of a service, for instance:

AppBundle/MyAwesomeService/MyAwesomeService.php // should be autowired
AppBundle/MyAwesomeService/Query/Query.php // should not

An exclusion rule would be welcome.

GuilhemN commented 7 years ago

Note that prototypes will be included in sf 3.3 and you'll be able to do what you want:


# app/config/services.yml
services:
    AppBundle\:
        resource: ../../src/AppBundle/MyAwesomeService
        autowire: true

    AppBundle\:
        resource: ../../src/AppBundle/MyAwesomeService/{Query}