Cannot autowire service in symfony
I'm trying to split one big service.yaml to few smaller files. In origin service.yaml I had
services:
_defaults:
autowire: true
autoconfigure: true
public: false
AppDomainCountryInfrastructureRepositoryCountryRepository:
public: true
class: AppDomainCountryInfrastructureRepositoryCountryRepository
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [AppDomainCountryEntityCountry]
Then I added import at the begining service.yam
imports:
- {resource: services/repositories.yaml}
repositories.yaml
services:
_defaults:
autowire: true
autoconfigure: true
public: true
AppDomainCountryInfrastructureRepositoryCountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [AppDomainCountryEntityCountry]
After that I started to get error
Cannot autowire service "AppDomainCountryInfrastructureRepositoryCount
ryRepository": argument "$class" of method "DoctrineORMEntityRepository::
__construct()" references class "DoctrineORMMappingClassMetadata" but no
such service exists.
What's wrong there?
https://pastebin.com/Uy85YJmc (service.yaml)
https://pastebin.com/ZesAw3sD (repositories.yaml)
symfony
|
show 9 more comments
I'm trying to split one big service.yaml to few smaller files. In origin service.yaml I had
services:
_defaults:
autowire: true
autoconfigure: true
public: false
AppDomainCountryInfrastructureRepositoryCountryRepository:
public: true
class: AppDomainCountryInfrastructureRepositoryCountryRepository
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [AppDomainCountryEntityCountry]
Then I added import at the begining service.yam
imports:
- {resource: services/repositories.yaml}
repositories.yaml
services:
_defaults:
autowire: true
autoconfigure: true
public: true
AppDomainCountryInfrastructureRepositoryCountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [AppDomainCountryEntityCountry]
After that I started to get error
Cannot autowire service "AppDomainCountryInfrastructureRepositoryCount
ryRepository": argument "$class" of method "DoctrineORMEntityRepository::
__construct()" references class "DoctrineORMMappingClassMetadata" but no
such service exists.
What's wrong there?
https://pastebin.com/Uy85YJmc (service.yaml)
https://pastebin.com/ZesAw3sD (repositories.yaml)
symfony
remove_defaultsfromrepositories/yaml. Also indentAppDomainCountryInfrastructureRepositoryCountryRepository
– Trix
Nov 16 '18 at 11:17
thanks, but the same :(
– akor
Nov 16 '18 at 11:21
Edit your question and put new files
– Trix
Nov 16 '18 at 11:22
I've added a links on pastebin
– akor
Nov 16 '18 at 11:25
Symfony version ?
– Trix
Nov 16 '18 at 11:27
|
show 9 more comments
I'm trying to split one big service.yaml to few smaller files. In origin service.yaml I had
services:
_defaults:
autowire: true
autoconfigure: true
public: false
AppDomainCountryInfrastructureRepositoryCountryRepository:
public: true
class: AppDomainCountryInfrastructureRepositoryCountryRepository
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [AppDomainCountryEntityCountry]
Then I added import at the begining service.yam
imports:
- {resource: services/repositories.yaml}
repositories.yaml
services:
_defaults:
autowire: true
autoconfigure: true
public: true
AppDomainCountryInfrastructureRepositoryCountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [AppDomainCountryEntityCountry]
After that I started to get error
Cannot autowire service "AppDomainCountryInfrastructureRepositoryCount
ryRepository": argument "$class" of method "DoctrineORMEntityRepository::
__construct()" references class "DoctrineORMMappingClassMetadata" but no
such service exists.
What's wrong there?
https://pastebin.com/Uy85YJmc (service.yaml)
https://pastebin.com/ZesAw3sD (repositories.yaml)
symfony
I'm trying to split one big service.yaml to few smaller files. In origin service.yaml I had
services:
_defaults:
autowire: true
autoconfigure: true
public: false
AppDomainCountryInfrastructureRepositoryCountryRepository:
public: true
class: AppDomainCountryInfrastructureRepositoryCountryRepository
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [AppDomainCountryEntityCountry]
Then I added import at the begining service.yam
imports:
- {resource: services/repositories.yaml}
repositories.yaml
services:
_defaults:
autowire: true
autoconfigure: true
public: true
AppDomainCountryInfrastructureRepositoryCountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [AppDomainCountryEntityCountry]
After that I started to get error
Cannot autowire service "AppDomainCountryInfrastructureRepositoryCount
ryRepository": argument "$class" of method "DoctrineORMEntityRepository::
__construct()" references class "DoctrineORMMappingClassMetadata" but no
such service exists.
What's wrong there?
https://pastebin.com/Uy85YJmc (service.yaml)
https://pastebin.com/ZesAw3sD (repositories.yaml)
symfony
symfony
edited Nov 16 '18 at 11:22
akor
asked Nov 16 '18 at 11:15
akorakor
437
437
remove_defaultsfromrepositories/yaml. Also indentAppDomainCountryInfrastructureRepositoryCountryRepository
– Trix
Nov 16 '18 at 11:17
thanks, but the same :(
– akor
Nov 16 '18 at 11:21
Edit your question and put new files
– Trix
Nov 16 '18 at 11:22
I've added a links on pastebin
– akor
Nov 16 '18 at 11:25
Symfony version ?
– Trix
Nov 16 '18 at 11:27
|
show 9 more comments
remove_defaultsfromrepositories/yaml. Also indentAppDomainCountryInfrastructureRepositoryCountryRepository
– Trix
Nov 16 '18 at 11:17
thanks, but the same :(
– akor
Nov 16 '18 at 11:21
Edit your question and put new files
– Trix
Nov 16 '18 at 11:22
I've added a links on pastebin
– akor
Nov 16 '18 at 11:25
Symfony version ?
– Trix
Nov 16 '18 at 11:27
remove
_defaults from repositories/yaml. Also indent AppDomainCountryInfrastructureRepositoryCountryRepository– Trix
Nov 16 '18 at 11:17
remove
_defaults from repositories/yaml. Also indent AppDomainCountryInfrastructureRepositoryCountryRepository– Trix
Nov 16 '18 at 11:17
thanks, but the same :(
– akor
Nov 16 '18 at 11:21
thanks, but the same :(
– akor
Nov 16 '18 at 11:21
Edit your question and put new files
– Trix
Nov 16 '18 at 11:22
Edit your question and put new files
– Trix
Nov 16 '18 at 11:22
I've added a links on pastebin
– akor
Nov 16 '18 at 11:25
I've added a links on pastebin
– akor
Nov 16 '18 at 11:25
Symfony version ?
– Trix
Nov 16 '18 at 11:27
Symfony version ?
– Trix
Nov 16 '18 at 11:27
|
show 9 more comments
2 Answers
2
active
oldest
votes
Use named arguments instead :
repositories.yaml
services:
AppDomainCountryInfrastructureRepositoryCountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments:
$class: '@AppDomainCountryEntityCountry'
thank you for help, but the same error again :(
– akor
Nov 16 '18 at 11:44
Do you have this error, with the provided snippet, insideservices.yamltoo ?
– Trix
Nov 16 '18 at 11:46
Inside repositories.yaml. When I have all repository declarations in services.yaml it works fine. But once I split it I get errror.
– akor
Nov 16 '18 at 11:49
try movingimportsat very top line above the parameters
– Trix
Nov 16 '18 at 11:57
no :( no changes
– akor
Nov 16 '18 at 12:01
add a comment |
You should not need to define the repository for the purposes of autowiring.
services.yaml:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
AppController:
resource: '../src/Controller'
tags: ['controller.service_arguments']
EntityCountry:
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass="AppRepositoryCountryRepository")
*/
class Country
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=255)
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
}
RepositoryCountryRepository:
<?php
namespace AppRepository;
use AppEntityCountry;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;
use SymfonyBridgeDoctrineRegistryInterface;
/**
* @method Country|null find($id, $lockMode = null, $lockVersion = null)
* @method Country|null findOneBy(array $criteria, array $orderBy = null)
* @method Country findAll()
* @method Country findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CountryRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Country::class);
}
}
And finally, your service:
<?php
namespace AppService;
use AppRepositoryCountryRepository;
class ExampleService
{
/**
* @var CountryRepository
*/
private $repository;
/**
* @param CountryRepository $repository
*/
public function __construct(CountryRepository $repository)
{
$this->repository = $repository;
}
}
The autowiring will see that you've injected that CountryRepository into the ExampleService constructor and handle the rest.
I'll try your version a little later. But correct me, will it work with $repository = $this->container->get('AppDomainBillingCounterpartyInfrastructureRepositoryCounterpartyRepository'); ? How to get repository from container in that case?
– akor
Nov 16 '18 at 12:08
That should work (or prefix with @ and use in the service definition), but as mentioned, sounds smelly because the container is being injected. Difficult to advise without knowing the exact problem but you should be able to configure your third party library and pass the things you need it to have rather than doing that.
– OK sure
Nov 16 '18 at 12:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53336775%2fcannot-autowire-service-in-symfony%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use named arguments instead :
repositories.yaml
services:
AppDomainCountryInfrastructureRepositoryCountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments:
$class: '@AppDomainCountryEntityCountry'
thank you for help, but the same error again :(
– akor
Nov 16 '18 at 11:44
Do you have this error, with the provided snippet, insideservices.yamltoo ?
– Trix
Nov 16 '18 at 11:46
Inside repositories.yaml. When I have all repository declarations in services.yaml it works fine. But once I split it I get errror.
– akor
Nov 16 '18 at 11:49
try movingimportsat very top line above the parameters
– Trix
Nov 16 '18 at 11:57
no :( no changes
– akor
Nov 16 '18 at 12:01
add a comment |
Use named arguments instead :
repositories.yaml
services:
AppDomainCountryInfrastructureRepositoryCountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments:
$class: '@AppDomainCountryEntityCountry'
thank you for help, but the same error again :(
– akor
Nov 16 '18 at 11:44
Do you have this error, with the provided snippet, insideservices.yamltoo ?
– Trix
Nov 16 '18 at 11:46
Inside repositories.yaml. When I have all repository declarations in services.yaml it works fine. But once I split it I get errror.
– akor
Nov 16 '18 at 11:49
try movingimportsat very top line above the parameters
– Trix
Nov 16 '18 at 11:57
no :( no changes
– akor
Nov 16 '18 at 12:01
add a comment |
Use named arguments instead :
repositories.yaml
services:
AppDomainCountryInfrastructureRepositoryCountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments:
$class: '@AppDomainCountryEntityCountry'
Use named arguments instead :
repositories.yaml
services:
AppDomainCountryInfrastructureRepositoryCountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments:
$class: '@AppDomainCountryEntityCountry'
answered Nov 16 '18 at 11:38
TrixTrix
10.2k85175
10.2k85175
thank you for help, but the same error again :(
– akor
Nov 16 '18 at 11:44
Do you have this error, with the provided snippet, insideservices.yamltoo ?
– Trix
Nov 16 '18 at 11:46
Inside repositories.yaml. When I have all repository declarations in services.yaml it works fine. But once I split it I get errror.
– akor
Nov 16 '18 at 11:49
try movingimportsat very top line above the parameters
– Trix
Nov 16 '18 at 11:57
no :( no changes
– akor
Nov 16 '18 at 12:01
add a comment |
thank you for help, but the same error again :(
– akor
Nov 16 '18 at 11:44
Do you have this error, with the provided snippet, insideservices.yamltoo ?
– Trix
Nov 16 '18 at 11:46
Inside repositories.yaml. When I have all repository declarations in services.yaml it works fine. But once I split it I get errror.
– akor
Nov 16 '18 at 11:49
try movingimportsat very top line above the parameters
– Trix
Nov 16 '18 at 11:57
no :( no changes
– akor
Nov 16 '18 at 12:01
thank you for help, but the same error again :(
– akor
Nov 16 '18 at 11:44
thank you for help, but the same error again :(
– akor
Nov 16 '18 at 11:44
Do you have this error, with the provided snippet, inside
services.yaml too ?– Trix
Nov 16 '18 at 11:46
Do you have this error, with the provided snippet, inside
services.yaml too ?– Trix
Nov 16 '18 at 11:46
Inside repositories.yaml. When I have all repository declarations in services.yaml it works fine. But once I split it I get errror.
– akor
Nov 16 '18 at 11:49
Inside repositories.yaml. When I have all repository declarations in services.yaml it works fine. But once I split it I get errror.
– akor
Nov 16 '18 at 11:49
try moving
imports at very top line above the parameters– Trix
Nov 16 '18 at 11:57
try moving
imports at very top line above the parameters– Trix
Nov 16 '18 at 11:57
no :( no changes
– akor
Nov 16 '18 at 12:01
no :( no changes
– akor
Nov 16 '18 at 12:01
add a comment |
You should not need to define the repository for the purposes of autowiring.
services.yaml:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
AppController:
resource: '../src/Controller'
tags: ['controller.service_arguments']
EntityCountry:
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass="AppRepositoryCountryRepository")
*/
class Country
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=255)
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
}
RepositoryCountryRepository:
<?php
namespace AppRepository;
use AppEntityCountry;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;
use SymfonyBridgeDoctrineRegistryInterface;
/**
* @method Country|null find($id, $lockMode = null, $lockVersion = null)
* @method Country|null findOneBy(array $criteria, array $orderBy = null)
* @method Country findAll()
* @method Country findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CountryRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Country::class);
}
}
And finally, your service:
<?php
namespace AppService;
use AppRepositoryCountryRepository;
class ExampleService
{
/**
* @var CountryRepository
*/
private $repository;
/**
* @param CountryRepository $repository
*/
public function __construct(CountryRepository $repository)
{
$this->repository = $repository;
}
}
The autowiring will see that you've injected that CountryRepository into the ExampleService constructor and handle the rest.
I'll try your version a little later. But correct me, will it work with $repository = $this->container->get('AppDomainBillingCounterpartyInfrastructureRepositoryCounterpartyRepository'); ? How to get repository from container in that case?
– akor
Nov 16 '18 at 12:08
That should work (or prefix with @ and use in the service definition), but as mentioned, sounds smelly because the container is being injected. Difficult to advise without knowing the exact problem but you should be able to configure your third party library and pass the things you need it to have rather than doing that.
– OK sure
Nov 16 '18 at 12:13
add a comment |
You should not need to define the repository for the purposes of autowiring.
services.yaml:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
AppController:
resource: '../src/Controller'
tags: ['controller.service_arguments']
EntityCountry:
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass="AppRepositoryCountryRepository")
*/
class Country
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=255)
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
}
RepositoryCountryRepository:
<?php
namespace AppRepository;
use AppEntityCountry;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;
use SymfonyBridgeDoctrineRegistryInterface;
/**
* @method Country|null find($id, $lockMode = null, $lockVersion = null)
* @method Country|null findOneBy(array $criteria, array $orderBy = null)
* @method Country findAll()
* @method Country findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CountryRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Country::class);
}
}
And finally, your service:
<?php
namespace AppService;
use AppRepositoryCountryRepository;
class ExampleService
{
/**
* @var CountryRepository
*/
private $repository;
/**
* @param CountryRepository $repository
*/
public function __construct(CountryRepository $repository)
{
$this->repository = $repository;
}
}
The autowiring will see that you've injected that CountryRepository into the ExampleService constructor and handle the rest.
I'll try your version a little later. But correct me, will it work with $repository = $this->container->get('AppDomainBillingCounterpartyInfrastructureRepositoryCounterpartyRepository'); ? How to get repository from container in that case?
– akor
Nov 16 '18 at 12:08
That should work (or prefix with @ and use in the service definition), but as mentioned, sounds smelly because the container is being injected. Difficult to advise without knowing the exact problem but you should be able to configure your third party library and pass the things you need it to have rather than doing that.
– OK sure
Nov 16 '18 at 12:13
add a comment |
You should not need to define the repository for the purposes of autowiring.
services.yaml:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
AppController:
resource: '../src/Controller'
tags: ['controller.service_arguments']
EntityCountry:
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass="AppRepositoryCountryRepository")
*/
class Country
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=255)
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
}
RepositoryCountryRepository:
<?php
namespace AppRepository;
use AppEntityCountry;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;
use SymfonyBridgeDoctrineRegistryInterface;
/**
* @method Country|null find($id, $lockMode = null, $lockVersion = null)
* @method Country|null findOneBy(array $criteria, array $orderBy = null)
* @method Country findAll()
* @method Country findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CountryRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Country::class);
}
}
And finally, your service:
<?php
namespace AppService;
use AppRepositoryCountryRepository;
class ExampleService
{
/**
* @var CountryRepository
*/
private $repository;
/**
* @param CountryRepository $repository
*/
public function __construct(CountryRepository $repository)
{
$this->repository = $repository;
}
}
The autowiring will see that you've injected that CountryRepository into the ExampleService constructor and handle the rest.
You should not need to define the repository for the purposes of autowiring.
services.yaml:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
AppController:
resource: '../src/Controller'
tags: ['controller.service_arguments']
EntityCountry:
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass="AppRepositoryCountryRepository")
*/
class Country
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=255)
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
}
RepositoryCountryRepository:
<?php
namespace AppRepository;
use AppEntityCountry;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;
use SymfonyBridgeDoctrineRegistryInterface;
/**
* @method Country|null find($id, $lockMode = null, $lockVersion = null)
* @method Country|null findOneBy(array $criteria, array $orderBy = null)
* @method Country findAll()
* @method Country findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CountryRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Country::class);
}
}
And finally, your service:
<?php
namespace AppService;
use AppRepositoryCountryRepository;
class ExampleService
{
/**
* @var CountryRepository
*/
private $repository;
/**
* @param CountryRepository $repository
*/
public function __construct(CountryRepository $repository)
{
$this->repository = $repository;
}
}
The autowiring will see that you've injected that CountryRepository into the ExampleService constructor and handle the rest.
answered Nov 16 '18 at 12:05
OK sureOK sure
1,660515
1,660515
I'll try your version a little later. But correct me, will it work with $repository = $this->container->get('AppDomainBillingCounterpartyInfrastructureRepositoryCounterpartyRepository'); ? How to get repository from container in that case?
– akor
Nov 16 '18 at 12:08
That should work (or prefix with @ and use in the service definition), but as mentioned, sounds smelly because the container is being injected. Difficult to advise without knowing the exact problem but you should be able to configure your third party library and pass the things you need it to have rather than doing that.
– OK sure
Nov 16 '18 at 12:13
add a comment |
I'll try your version a little later. But correct me, will it work with $repository = $this->container->get('AppDomainBillingCounterpartyInfrastructureRepositoryCounterpartyRepository'); ? How to get repository from container in that case?
– akor
Nov 16 '18 at 12:08
That should work (or prefix with @ and use in the service definition), but as mentioned, sounds smelly because the container is being injected. Difficult to advise without knowing the exact problem but you should be able to configure your third party library and pass the things you need it to have rather than doing that.
– OK sure
Nov 16 '18 at 12:13
I'll try your version a little later. But correct me, will it work with $repository = $this->container->get('AppDomainBillingCounterpartyInfrastructureRepositoryCounterpartyRepository'); ? How to get repository from container in that case?
– akor
Nov 16 '18 at 12:08
I'll try your version a little later. But correct me, will it work with $repository = $this->container->get('AppDomainBillingCounterpartyInfrastructureRepositoryCounterpartyRepository'); ? How to get repository from container in that case?
– akor
Nov 16 '18 at 12:08
That should work (or prefix with @ and use in the service definition), but as mentioned, sounds smelly because the container is being injected. Difficult to advise without knowing the exact problem but you should be able to configure your third party library and pass the things you need it to have rather than doing that.
– OK sure
Nov 16 '18 at 12:13
That should work (or prefix with @ and use in the service definition), but as mentioned, sounds smelly because the container is being injected. Difficult to advise without knowing the exact problem but you should be able to configure your third party library and pass the things you need it to have rather than doing that.
– OK sure
Nov 16 '18 at 12:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53336775%2fcannot-autowire-service-in-symfony%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
remove
_defaultsfromrepositories/yaml. Also indentAppDomainCountryInfrastructureRepositoryCountryRepository– Trix
Nov 16 '18 at 11:17
thanks, but the same :(
– akor
Nov 16 '18 at 11:21
Edit your question and put new files
– Trix
Nov 16 '18 at 11:22
I've added a links on pastebin
– akor
Nov 16 '18 at 11:25
Symfony version ?
– Trix
Nov 16 '18 at 11:27