mirzik
mirzik

Reputation: 33

symfony2 service container linking / clone service container

I want to link one service container to another, that is already exist, for example:

acme.user.repository:
    class:            '%acme.user.repository.class%'
    arguments:        ['%acme.user.repository.argument%']
    factory_service:  doctrine.orm.entity_manager
    factory_method:   getRepository

Now I want to link this service to another, something like this:

acme.admin.repository = acme.user.repository

So, I will get the same instance when I call $container->get('acme.admin.repository'); as when I call $container->get('acme.user.repository');

Upvotes: 1

Views: 764

Answers (2)

Cerad
Cerad

Reputation: 48865

Use an alias to avoid certain problems:

services:

    acme.admin.repository:
        alias: acme.user.repository

Upvotes: 2

pleerock
pleerock

Reputation: 18836

I think you can link your services this way:

acme.admin.repository: '@acme.user.repository'

Upvotes: 1

Related Questions