Message-ID: <67960141.2862.1485851037388.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2861_468068289.1485851037388" ------=_Part_2861_468068289.1485851037388 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Service Container

Service Container

=20
=20
=20
=20

Definition

A service container, (aka DIC, Dependency Inje= ction Container) is a special object that greatly facilitates dependen= cies resolution in your application and sits on Dependency Injection design pattern. Basically, this design pattern pr= oposes to inject all needed objects and configuration into your business lo= gic objects (aka services). It avoids the massive use of s= ingletons, global variables or complicated factories and thus makes your co= de much more readable and testable. It avoids "magic."

The main issue with dependency injection is how to resolve your dependen= cies 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 an= d their dependencies. Basically, each time you need a service, you may ask = the service container for it, which will either build it with the configura= tion you provided, or give you an existing instance if it is already availa= ble.

In eZ Platform

eZ Platform uses Symfony servic= e container.

It is very powerful and highly configurable. We encourage you to read it= s dedicated documentation as it will help you understand how eZ Platform se= rvices 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 creat= e the PHP class and declare it as a service in the DIC configuration with t= he twig.extension tag (see Symfony cookbook entry for a full example).

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

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

Core & API

Tag name Usage

router

Adds a specific router to the chai= n router

twig.loader

Registers a template loader for tw= ig

ezpublish.content_view_pr= ovider

Registers a ContentViewProvider fo= r template selection depending on content/Location being viewed

ezpublish.storageEngine

Registers a storage engine in the = Repository factory

ezpublish.fieldTy= pe

Registers a Field Type

Legacy

Tag name Usage

ezpublish.storage= Engine.legacy.converter

Registers a converter for a Field = Type in legacy storage engine

ezpublish.fieldTy= pe.externalStorageHandler

Registers an external storage hand= ler for a Field Type

ezpublish.fieldTy= pe.externalStorageHandler.gateway

Registers an external storage gate= way for a Field Type in legacy storage engine
=20
=20
=20
=20

 

=20
=20
=20
------=_Part_2861_468068289.1485851037388--