General

  eZ Systems Website
  Technical documentation
  Editor documentation

This Documentation contains:
 
Technical documentation:



⚠ WARNING ! This documentation is deprecated !

Please go to the current Technical Documentation

Skip to end of metadata
Go to start of metadata

Definition

A service container, (aka DIC, Dependency Injection Container) is a special object that greatly facilitates dependencies resolution in your application and sits on Dependency Injection design pattern. Basically, this design pattern proposes to inject all needed objects and configuration into your business logic objects (aka services). It avoids the massive use of singletons, global variables or complicated factories and thus makes your code much more readable and testable. It avoids "magic."

The main issue with dependency injection is how to resolve your dependencies for your services. This is where the service container comes into play. The role of a service container is to build and maintain your services and their dependencies. Basically, each time you need a service, you may ask the service container for it, which will either build it with the configuration you provided, or give you an existing instance if it is already available.

In eZ Platform

eZ Platform uses Symfony service container .

It is very powerful and highly configurable. We encourage you to read its dedicated documentation as it will help you understand how eZ Platform services are made:

Service tags

Service tags in Symfony DIC are a useful way of dedicating services to a specific purpose. They are usually used for extension points.

For instance, if you want to register a Twig extension to add custom filters, you will need to create the PHP class and declare it as a service in the DIC configuration with the twig.extension tag (see Symfony cookbook entry for a full example).

eZ Platform exposes several features this way (see the list of core service tags). This is for example the case for Field Types.

You will find all service tags exposed by Symfony in its reference documentation.