Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add alias to existing service not working #28413

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
videni opened this issue Sep 9, 2018 · 2 comments
Closed

add alias to existing service not working #28413

videni opened this issue Sep 9, 2018 · 2 comments

Comments

@videni
Copy link

videni commented Sep 9, 2018

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false
   App\AppBundle\Checker\PromotionCouponEligibilityChecker: ~
  
   App\Bundle\AppBundle\Checker\Eligibility\PromotionCouponEligibilityCheckerInterface:
        alias:  “@App\AppBundle\Checker\PromotionCouponEligibilityChecker”

As you can see the alias and its service are at same file, but it gives a error when autowire the interface in a class constructor.

ymfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "“@App\AppBundle\Checker\PromotionCouponEligibilityChecker”". in /Users/www/AppBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1001
@videni
Copy link
Author

videni commented Sep 9, 2018

I change it to this , it works now

   App\Bundle\ AppBundle\Checker\Eligibility\PromotionCouponEligibilityCheckerInterface: '@App\ AppBundle\Checker\PromotionCouponEligibilityChecker'

@xabbuh
Copy link
Member

xabbuh commented Sep 9, 2018

When being explicit by using the alias option, you must omit the @ character. This means the following configuration would work as well:

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false
   App\AppBundle\Checker\PromotionCouponEligibilityChecker: ~
  
   App\Bundle\AppBundle\Checker\Eligibility\PromotionCouponEligibilityCheckerInterface:
        alias:  “App\AppBundle\Checker\PromotionCouponEligibilityChecker”

I close here as this is not a bug.

@xabbuh xabbuh closed this as completed Sep 9, 2018
fabpot added a commit that referenced this issue Sep 23, 2018
…ice is not found (xabbuh)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[DependencyInjection] improved message when alias service is not found

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28413
| License       | MIT
| Doc PR        |

When using the YAML config format, it can be confusing that you need to
prefix the aliased service id with an `@` character when passing it as
a string, but that you have to omit it when using the `alias` attribute:

```yaml
foo: '@app\Foo'

foo:
    alias: 'App\Foo'
```

This commit will enhance the generated error message in cases where the
aliased service id is prefixed with the `@` character in the `alias`
option like this:

```yaml
foo:
    alias: '@app\Foo'
```

Commits
-------

280ecbc improved message when alias service is not found
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