Chapters
23 Chapters
|
2:20:28
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
05.
The Service Container & Autowiring
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial also works great for Symfony 6!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.3.0 || ^8.0.0",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.1
"sentry/sentry-symfony": "^4.0", // 4.0.3
"symfony/asset": "5.0.*", // v5.0.11
"symfony/console": "5.0.*", // v5.0.11
"symfony/debug-bundle": "5.0.*", // v5.0.11
"symfony/dotenv": "5.0.*", // v5.0.11
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/framework-bundle": "5.0.*", // v5.0.11
"symfony/monolog-bundle": "^3.0", // v3.6.0
"symfony/profiler-pack": "*", // v1.0.5
"symfony/routing": "5.1.*", // v5.1.11
"symfony/twig-pack": "^1.0", // v1.0.1
"symfony/var-dumper": "5.0.*", // v5.0.11
"symfony/webpack-encore-bundle": "^1.7", // v1.8.0
"symfony/yaml": "5.0.*" // v5.0.11
},
"require-dev": {
"symfony/maker-bundle": "^1.15", // v1.23.0
"symfony/profiler-pack": "^1.0" // v1.0.5
}
}
4 Comments
I am having a problem with dependency injection in Symfony 5.4 and I have no clue what the problem is....
I am trying to inject entity manager into a constraint validator. It begins like this:
And I have the following under services: in my services.yaml file:
However, the constructor is always called with zero arguments when I try to use it. debug:autowiring says there's no autowirable classes or services for that class. What could be going wrong?
Hi
Have you tried to use
EntityManagerInterfaceas a wireable class? also if you have autoconfigure and autowire enabled then you don't need to specify configuration for this class.Cheers!
I would like to aks about peerfomance of autowiring (auto:true). Is it load whole the folder or only when you real use a class? It it make sense to disable autowiring on entities folder with 30-40 classes? Thanks for great tutorials!
Hey triemli
That's a good question. When you enable autowiring, what it does is to tell Symfony to inject the correct services into your class based on the type-hint or bind-ed variables. This may have a performance impact because it'll have to look up the metadata and other things BUT this happens only once, when the container is compiled, after that, this process is very fast. So, in other words all the heavy work for setting up the container gets cached and dumped into a final file which will be used for the subsequent requests.
I strongly recommend you to enable autowiring and autoconfigure, those features makes working with Symfony a delight.
Cheers!
"Houston: no signs of life"
Start the conversation!