Javier
Javier

Reputation: 393

Symfony 3.4.4 + Sonata ADmin Bundle + already existing entities

I'm starting with Symfony 3.4.4 + SonataAdmin Bundle.

Everything works correctly for me.

I already have entities generated and in the integration of entities within SonataAdmin bundle by means of "php bin/console sonata:admin:generate" entities are generated in "src/AppBundle/Resources/config/services.yml

And that file is not integrated into my bundle.

I have read that using Dependency Injection is the most correct way to load that file, but I do not know how it is done.

Can someone explain to me how to install dependency injection and that this file be loaded correctly by means of the "good practices" of symfony?

Upvotes: 0

Views: 196

Answers (1)

Jim Panse
Jim Panse

Reputation: 2270

I think you are confusing something. Dependency injection is a principle in software development to decouple a classes dependency from other classes by not setting properties inside a class directly. Instead you give it for example to the constructor or set it afterwards by a public setter method. With this your classes are replaceable and thats beneficial especially for testing your source code.

So you cant install a software development principle.

And your entities are not generated in your services.yml. Your services are defined here and your entities normally going to src/AppBundle/Entity.

Symfony/Sonata is using dependency injection by defining services in the services.yml and telling them, which parameters they will get.

For example

services:
    mailer:
        class:     Mailer
        arguments: ['%mailer.transport%']

Here the mailer.transport parameter will be injected to the Mailers class constructor.

There are many yml files in your app/config folder, but the all are united in the config.yml

So if you have no instruction like

- { resource: "@AppBundle/Resources/config/services.yml" } 

in your app/config/config.yml your services will never be loaded.

Upvotes: 1

Related Questions