+ All Categories
Home > Software > Symfony Dependency Injection (DI) in Practice - Denis Malavsky, Grossum

Symfony Dependency Injection (DI) in Practice - Denis Malavsky, Grossum

Date post: 15-Jul-2015
Category:
Upload: grossum
View: 386 times
Download: 2 times
Share this document with a friend
Popular Tags:
24
Symfony Dependency Injection in Practice (Denis Malavsky, Grossum)
Transcript

Symfony Dependency Injection in Practice

(Denis Malavsky, Grossum)

WHAT IS DEPENDENCY INJECTION

WWW.GROSSUM.COM

Dependency injection is a software design pattern in which one or more dependencies (or services) are injected, or passed by reference, into a dependent object (or client) and are made part of the client's state. The pattern separates the creation of a client's dependencies from its own behavior, which allows program designs to be loosely coupled and to follow the dependency inversion and single responsibility principles.

It directly contrasts with the service locator pattern, which allows clients to know about the system they use to find dependencies

SYMFONY CAFÉ KYIV

SETTING UP THE CONTAINER with Configuration Files

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

TYPES OF INJECTION

• Constructor Injection

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

TYPES OF INJECTION

• Setter Injection

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

TYPES OF INJECTION

• Property Injection

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

INTRODUCTION TO PARAMETERS

• Parameters in Configuration Files • Array Parameters • Constants as Parameters • PHP Keywords in XML

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

WORKING WITH CONTAINER SERVICE DEFINITIONS

• Getting and Setting Service Definitions:

• Class

WWW.GROSSUM.COM

$container->hasDefinition($serviceId); $container->getDefinition($serviceId); $container->findDefinition($serviceId); $container->setDefinition($id, $definition);

$definition->getClass(); $definition->setClass($class); // Fully qualified class name as string

SYMFONY CAFÉ KYIV

WORKING WITH CONTAINER SERVICE DEFINITIONS

• Constructor Arguments

• Method Calls

WWW.GROSSUM.COM

$definition->getArguments(); $definition->getArgument($index); $definition->addArgument($argument); $definition->replaceArgument($index, $argument); $definition->setArguments($arguments);

$definition->getMethodCalls(); $definition->addMethodCall($method, $arguments); $definition->setMethodCalls($methodCalls);

SYMFONY CAFÉ KYIV

MANAGING CONFIGURATION WITH EXTENSIONS

• Let’s take a look at the code.

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

CREATING A COMPILER PASS

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

CONTROLLING THE PASS ORDERING

• PassConfig::TYPE_BEFORE_OPTIMIZATION • PassConfig::TYPE_OPTIMIZE • PassConfig::TYPE_BEFORE_REMOVING • PassConfig::TYPE_REMOVE • PassConfig::TYPE_AFTER_REMOVING

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

WORKING WITH TAGGED SERVICES

• Define Services with a custom Tag

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

WORKING WITH TAGGED SERVICES

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

WORKING WITH TAGGED SERVICES

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

WORKING WITH TAGGED SERVICES

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

USING A FACTORY TO CREATE SERVICES

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

USING A FACTORY TO CREATE SERVICES

• Passing Arguments to the Factory Method

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

MANAGING COMMON DEPENDENCIES WITH PARENT SERVICES

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

MANAGING COMMON DEPENDENCIES WITH PARENT SERVICES

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

MANAGING COMMON DEPENDENCIES WITH PARENT SERVICES

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

ADVANCED CONTAINER CONFIGURATION

• Marking Services as public / private

• Aliasing

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

ADVANCED CONTAINER CONFIGURATION

• Requiring Files

• Decorating Services

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV

THANKS! DENIS MALAVSKY Company: Grossum Phone: +38 (063) 478-2449 E-mail: [email protected] Skype: malavskuy

WWW.GROSSUM.COM SYMFONY CAFÉ KYIV


Recommended