DunglasActionBundle icon indicating copy to clipboard operation
DunglasActionBundle copied to clipboard

A way to avoid autowiring in specific classes

Open magarzon opened this issue 8 years ago • 2 comments

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...

magarzon avatar Feb 20 '17 12:02 magarzon

+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.

bpolaszek avatar Apr 04 '17 10:04 bpolaszek

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}

GuilhemN avatar Apr 05 '17 11:04 GuilhemN