4

I'm trying to create my first service in a symfony 2 application and I get this error :

InvalidArgumentException: There is no extension able to load the
configuration for "my_app.myservice" (in
/path/to/src/MyApp/MyBundle/DependencyInjection/../Resources/config/services.yml).
Looked for namespace "my_app.myservice", found none.

It seems there's a problem in my configuration but I don't see what it is.

Here's my services.yml

services:
my_app.myservice:
    class: MyApp\MyBundle\Service\MyService

And my service looks like this

<?php
namespace MyApp\MyBundle\Service;

class MyService
{
    public function run()
    {
        echo "hello world";
    }
}

Thanks for help !

2 Answers 2

2

Just to be sure - do you have proper indentation in the services.yml?

It should be:

services:
  my_app.myservice:
    class: MyApp\MyBundle\Service\MyService 

not:

services:
my_app.myservice:
  class: MyApp\MyBundle\Service\MyService
Sign up to request clarification or add additional context in comments.

1 Comment

That's it !! Arf ! It was so obvious and simple. I can't believe I've waste so much time on something like this. Thanks for helping.
0

Do you have any argument in your service's constructor ?

For example i pass the logger in all my services.

it's result that i have to pass it in my service.yml


service.yml

services:
    blog:
        class:Site\Backend\BlogBundle\Service\BlogService
        arguments: [@logger]
        tags:
            - { name: monolog.logger, channel: blog}

BlogService

public function __construct(LoggerInterface $logger){
    $this->logger = $logger;
}

1 Comment

Nope I don't have any argument in the constructor. In fact I didn't have any constructor at all in the service. I tryed to add one but it doesn't work any better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.