Symfony

Dependency Injection & Services

Service container, autowiring, service configuration, tags, decoration, aliases

24 preguntas de entrevista·
Mid-Level
1

What is the main role of the service container in Symfony?

Respuesta

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.

2

What is autowiring in Symfony?

Respuesta

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.

3

What is the difference between a public and a private service in Symfony?

Respuesta

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.

4

How to inject a service into a Symfony controller using autowiring?

5

What does the autoconfigure option do in Symfony service configuration?

+21 preguntas de entrevista

Domina Symfony para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis