
Dependency Injection & Services
Service container, autowiring, service configuration, tags, decoration, aliases
1What is the main role of the service container in Symfony?
What is the main role of the service container in Symfony?
Answer
The service container (or Dependency Injection Container) is responsible for creating, configuring, and managing the lifecycle of all application services. It enables automatic dependency injection into classes, promoting loose coupling and facilitating unit testing.
2What is autowiring in Symfony?
What is autowiring in Symfony?
Answer
Autowiring is a feature that allows the container to automatically resolve service dependencies by analyzing the type-hints of constructor parameters. This avoids having to manually configure each dependency injection in YAML or PHP files.
3What is the difference between a public and a private service in Symfony?
What is the difference between a public and a private service in Symfony?
Answer
A public service can be retrieved directly from the container via get(), while a private service can only be injected as a dependency of other services. Since Symfony 4, services are private by default to improve performance and encourage dependency injection over direct container access.
How to inject a service into a Symfony controller using autowiring?
What does the autoconfigure option do in Symfony service configuration?
+21 interview questions
Other Symfony interview topics
Modern PHP (8.1+)
Symfony Basics
Routing & Controllers
Twig & Templates
Doctrine ORM Basics
Symfony Forms
Data Validation
Security & Authentication
Doctrine Advanced
API Platform
Serializer Component
Events & Event Subscribers
Console & Commands
Messenger Component
HTTP Client
Cache & Performance
Workflow Component
Testing Symfony
Mailer Component
Translations & i18n
EasyAdmin Bundle
Symfony Architecture
Performance & Optimization
Security Advanced
Custom Bundles
Microservices with Symfony
Real-time & WebSockets
Deployment & DevOps
Master Symfony for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free