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

Skip to content
[DX] Service declaration annotation #23758
Closed
@Vinorcola

Description

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0