Symfony

Dependency Injection & Services

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

24 питань зі співбесід·
Mid-Level
1

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

Відповідь

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?

Відповідь

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?

Відповідь

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 питань зі співбесід

Опануй Symfony для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно