Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

Making *all* classes in src/AppBundle available as services #1070

Merged
merged 1 commit into from
May 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@ services:
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, form types, etc.
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false

# loads services from whatever directories you want (you can add directories!)
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
AppBundle\:
resource: '../../src/AppBundle/{Command,Form,EventSubscriber,Twig,Security}'
resource: '../../src/AppBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../../src/AppBundle/{Entity,Repository}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about excluding controllers here explicitly too? They are registered below anyway (and excluding them here may prevent some confusion).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mixed. On one hand, I want exclude to be a detail that people don't think about or even notice. In fact, the only reason it's even needed is for Entity, to avoid a weird situation where the new "controller service args" functionality keeps a reference to them so they're not removed. Adding Controller to it makes this setting seem even more important.

On the other hand, especially in the future if we remove the "auto-register services" functionality from autowiring, exclude will be a nice way to explicitly prevent things from being used as services.

So, I kind of think we should not add it. In theory, we could also add AppBundle.php... but I think we should keep it minimal instead.


# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
AppBundle\Controller\:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']

# add more services, or override services that need manual wiring
# AppBundle\Service\ExampleService:
# arguments:
# $someArgument: 'some_value'