I’m only using Symfony DI, Http, Kernel, Routing components in my project following Create your own PHP Framework (https://symfony.com/doc/current/create_framework/index.html). Project, on which I specify, that @cerad was of great help. Thanks again. It’s ok with Service and Controller dependency injection.
But now I encounter a new difficulty with instantiate repository in dependency injection.
I added symfony/orm-pack to use ServiceEntityRepository.
As specified in the comments my concern is a problem of approach.
My question is poorly put and the context is not sufficiently clear. Still in a learning environment, I try to implement the concepts of Clean Architecture and Domain Driven Design.
In this idea of partitioning and independence, I also try to better master my Framework by starting from almost nothing, to add as I go, only what I need.
Still following the comments I no longer use symfony / orm-pack but doctrine / dbal.
There is still a lot to do but it works.
// Doctrine $containerBuilder->register(ExampleAppDomainClientEntityClientRepository::class, InfrastructurePersistenceDoctrineClientDoctrineClientRepository::class) ->setArguments([new Reference('service_container')]); $containerBuilder->register(ExampleAppDomainClientUseCaseGetClientGetClient::class, ExampleAppDomainClientUseCaseGetClientGetClient::class) ->setArguments([new Reference(ExampleAppDomainClientEntityClientRepository::class)]); $containerBuilder->register(ExampleAppPresentationClientGetClientHtmlPresenter::class, ExampleAppPresentationClientGetClientHtmlPresenter::class); $containerBuilder->register(InfrastructureViewGetClientView::class, InfrastructureViewGetClientView::class); $containerBuilder->register(InfrastructureControllerClientController::class, InfrastructureControllerClientController::class) ->setArguments([ new Reference(ExampleAppDomainClientUseCaseGetClientGetClient::class), new Reference(ExampleAppPresentationClientGetClientHtmlPresenter::class), new Reference(InfrastructureViewGetClientView::class) ]);
Returns are ok now.
https://github.com/Monnomcjo/symfony-simplex is updated too.
Next step, add .env, and conf files type services.yaml
Since your problem right now is with the missing
doctrine.orm.entity_manager I think the best way to see how Symfony does it, is to look at the DoctrineBundle. Specifically at DependencyInjection/DoctrineExtension.php and the Configuration from which the config values are received. You might also want to take a look at the service definitions.
The Extension class takes the configuration (usually in your config/packages/doctrine.yaml) that is validated through the Configuration and then updates the service definitions under Resources/config. This approach is rather complex, but it will help you see how things are connected in Symfony.
Alternatively you can look at the Doctrine Docs to see how to get an EntityManager and then convert this into Symfony Service Container registration:
$isDevMode = true; $proxyDir = null; $cache = null; $useSimpleAnnotationReader = false; $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode, $proxyDir, $cache, $useSimpleAnnotationReader); // or if you prefer yaml or XML //$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode); //$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode); // database configuration parameters $conn = array( 'driver' => 'pdo_sqlite', 'path' => __DIR__ . '/db.sqlite', ); // obtaining the entity manager $entityManager = EntityManager::create($conn, $config);
You can see the EntityManager::create in the service definition link above. How you do this in your application largely depends on how close you want to build it to Symfony and what and how you want to configure around Doctrine.