8000 [DX] Service declaration annotation · Issue #23758 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DX] Service declaration annotation #23758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Vinorcola opened this issue Aug 2, 2017 · 1 comment
Closed

[DX] Service declaration annotation #23758

Vinorcola opened this issue Aug 2, 2017 · 1 comment

Comments

@Vinorcola
Copy link
Q A
Bug report? no
Feature request? no
BC Break report? no
RFC? yes
Symfony version 3.4

The new system of auto-loading services into the conatiner have some caveats when your bundle contains a lot of "value-object" that must not de declared as services. Those value-object always causes trouble because they require values in the constructor (which is the point of value-objects).

Of course, one can simply setup the exclude option when declaring the service auto-loading:

AppBundle\:
    resource: '../../src/AppBundle/*'
    exclude: '../../src/AppBundle/{Entity,Repository,SomeModel/SomeValueObjectA,SomeModel/SomeValueObjectB}'

But it can become very complicated if you need to exclude a lot of objects. One can simply put the value-objects into a dedicated directory. But one may prefer to have the value-objects in the same directory than the service they are related to.

Rather than a auto-opt-in and explicit-opt-out system, we could add an explicit-opt-in system based on annotations (the same way for routing):

AppBundle\:
    resource: '../../src/AppBundle/*'
    type: annotation

Then, this configuration will only load classes that have a @Service annotation:

<?php

namespace AppBundle\SomeModel;

use Wherever\It\Should\Leave\Annotation\Service;

/**
 * @Service
 */
class MyModel
{
    // ...
}

The best place for it is the FrameworkExtraBundle I guess...

@chalasr
Copy link
Member
chalasr commented Aug 2, 2017

This has already been proposed and rejected in the past (we even gave it a try and finally decided to improve supported config formats instead). See #21103 for the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0