Symfony applications are built around services and a dependency injection container. The container constructs objects and supplies their dependencies, making application wiring explicit and testable.
Services and autowiring
A service is an object that performs a focused task, such as sending notifications or coordinating a workflow. Service configuration tells Symfony how to construct it. Autowiring can infer dependencies from type declarations, but explicit configuration remains useful when multiple implementations exist or when a scalar setting is required.
Bundles and application code
Bundles package reusable Symfony functionality. Modern application-specific code generally belongs in the application's own namespaces rather than being wrapped in a bundle solely to create folders. Use a bundle when you are building functionality intended to be reused across applications.
Keep dependencies visible
Inject interfaces where substitution matters. Avoid fetching arbitrary services from the container inside domain code; that hides dependencies and makes tests harder. Configure environment-specific values through supported configuration mechanisms and keep secrets out of source control.
Inspect the container
Use Symfony console commands to inspect registered services and configuration. This helps explain what the framework actually built rather than relying on assumptions.
Further reading
- Symfony service container: https://symfony.com/doc/current/service_container.html
- Symfony bundles: https://symfony.com/doc/current/bundles.html