Skip to content

Document injecting a dictionary into a service via autowiring #154

@tacman

Description

@tacman

You will be able to retreive it through the dictionaries collection service:

$dictionaries = $container->get(\Knp\DictionaryBundle\Dictionary\Collection::class);
$dictionary   = $dictionaries['my_dictionary'];

Is there a way to inject a dictionary into a service, like Workflows? That is, if I want to inject a specific workflow into a service

public function __construct(private Symfony\Component\Workflow\WorkflowInterface $projectStateMachine)

what I'm currently doing is injecting the whole collection and extracting the one I want

    private Dictionary $voteDictionary;

    public function __construct(
                                private Dictionary\Collection $dictionaryCollection,
)
    {
        $this->voteDictionary = $this->dictionaryCollection['vote'];

What I'd like to do is

public function __construct(private DictionaryInterface $voteDictionary)

That is, bin/console debug:container dictionary would also show how to inject a specific dictionary. I don't think this is possible now, but if someone can point me in the right direction as to how to do this, maybe I can add it. Thanks.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions