Laravels IoC Container

Niklas Modess
Niklas ModessCode Monkey at Nevertheless
Laravels
IoC
container
Me, myself& I
Niklas Modess
Web architect at Nevertheless
@niklasmodess
http://www.codingswag.com
Deploying PHP
Applications
» Currently writing
» Deploy process for PHP
applications
» https://leanpub.com/
deploying-php-applications
Symfony
November Camp
» Full day of PHP/Symfony @
Scandic Grand Central
» 14th of November
» I will give a talk on
"Deploying PHP
applications"
» http://www.symfony.se/
november-camp/
The topic ofthistalk
is kind ofalie...“Laravels IoC container”
Thetruth...
The Laravelapplication
isan IoC container
class Application extends Container [...] {
[...]
}
Dependencyinjection
comes first
App::make('foo');
Instantiation
App::bind('foo', function()
{
return new FooBar;
});
$foo = App::make('foo'); // instance of FooBar
Or resolvethe class directly
$foo = App::make('FooBar'); // same as 'new FooBar';
Singleton objects
App::singleton('bar', function()
{
return new BarFoo;
});
$foo = App::make('bar'); // instance of BarFoo
Swapoutbinded objects
$foo = new Foo;
App::instance('foo', $foo);
» Great for testing
Internal
dependencies
Taylor magic™
Automatic dependencyresolving
class OrderController extends BaseController {
protected $orders;
public function __construct(OrderRepository $orders)
{
$this->orders = $orders;
}
public function getIndex()
{
$all = $this->orders->all();
return View::make('orders', compact('all'));
}
}
Instead of
$orderRepository = new OrderRepository;
$orderController = new OrderController($orderRepository);
We use
$orderController = App::make('OrderController');
Couldalso beachievedthisway
$orderRepository = new OrderRepository;
$orderController = App::make('OrderController', [$orderRepository]);
More awesome stuff
* Service providers
* Interface binding
Questions?
1 of 17

Recommended

What's Kotlin and Why? by
What's Kotlin and Why?What's Kotlin and Why?
What's Kotlin and Why?Pouya Heydari
43 views13 slides
codeigniter by
codeignitercodeigniter
codeigniterMohamed Syam
121 views26 slides
NCUG 2019: Super charge your API’s with Reactive streams by
NCUG 2019: Super charge your API’s with Reactive streamsNCUG 2019: Super charge your API’s with Reactive streams
NCUG 2019: Super charge your API’s with Reactive streamsFrank van der Linden
3.9K views43 slides
Javascript internals by
Javascript internalsJavascript internals
Javascript internalsAyush Sharma
471 views21 slides
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (... by
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...Frank van der Linden
4K views48 slides
Adrian Rapan - Re-purposing Webdriver for Security Testing - EuroSTAR 2012 by
Adrian Rapan - Re-purposing Webdriver for Security Testing - EuroSTAR 2012Adrian Rapan - Re-purposing Webdriver for Security Testing - EuroSTAR 2012
Adrian Rapan - Re-purposing Webdriver for Security Testing - EuroSTAR 2012TEST Huddle
558 views22 slides

More Related Content

Similar to Laravels IoC Container

PHP Conference - Phalcon hands-on by
PHP Conference - Phalcon hands-onPHP Conference - Phalcon hands-on
PHP Conference - Phalcon hands-onJackson F. de A. Mafra
1.9K views85 slides
Phalcon - Giant Killer by
Phalcon - Giant KillerPhalcon - Giant Killer
Phalcon - Giant KillerJackson F. de A. Mafra
1.9K views49 slides
Composing WSGI apps and spellchecking it all by
Composing WSGI apps and spellchecking it allComposing WSGI apps and spellchecking it all
Composing WSGI apps and spellchecking it allRodolfo Carvalho
470 views25 slides
Using JHipster for generating Angular/Spring Boot apps by
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsYakov Fain
1.5K views38 slides
Using Jhipster 4 for Generating Angular/Spring Boot Apps by
Using Jhipster 4 for Generating Angular/Spring Boot AppsUsing Jhipster 4 for Generating Angular/Spring Boot Apps
Using Jhipster 4 for Generating Angular/Spring Boot AppsVMware Tanzu
5.3K views38 slides
Design patterns by
Design patternsDesign patterns
Design patternsJason Austin
1.2K views146 slides

Similar to Laravels IoC Container(20)

Composing WSGI apps and spellchecking it all by Rodolfo Carvalho
Composing WSGI apps and spellchecking it allComposing WSGI apps and spellchecking it all
Composing WSGI apps and spellchecking it all
Rodolfo Carvalho470 views
Using JHipster for generating Angular/Spring Boot apps by Yakov Fain
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
Yakov Fain1.5K views
Using Jhipster 4 for Generating Angular/Spring Boot Apps by VMware Tanzu
Using Jhipster 4 for Generating Angular/Spring Boot AppsUsing Jhipster 4 for Generating Angular/Spring Boot Apps
Using Jhipster 4 for Generating Angular/Spring Boot Apps
VMware Tanzu5.3K views
Symfony Components 2.0 on PHP 5.3 by Fabien Potencier
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3
Fabien Potencier18.6K views
Selenium & PHPUnit made easy with Steward (Berlin, April 2017) by Ondřej Machulda
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Ondřej Machulda1.4K views
Java Stammtisch Würzburg - CONAIR by Matthias Reining
Java Stammtisch Würzburg - CONAIRJava Stammtisch Würzburg - CONAIR
Java Stammtisch Würzburg - CONAIR
Matthias Reining1.5K views
Hands-on with the Symfony2 Framework by Ryan Weaver
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 Framework
Ryan Weaver9.3K views
Flask Introduction - Python Meetup by Areski Belaid
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
Areski Belaid4.4K views
State ofappdevelopment by gillygize
State ofappdevelopmentState ofappdevelopment
State ofappdevelopment
gillygize397 views
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP by Mykola Novik
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOPHOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
Mykola Novik3.5K views

Recently uploaded

ADDO_2022_CICID_Tom_Halpin.pdf by
ADDO_2022_CICID_Tom_Halpin.pdfADDO_2022_CICID_Tom_Halpin.pdf
ADDO_2022_CICID_Tom_Halpin.pdfTomHalpin9
5 views33 slides
Electronic AWB - Electronic Air Waybill by
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill Freightoscope
5 views1 slide
Airline Booking Software by
Airline Booking SoftwareAirline Booking Software
Airline Booking SoftwareSharmiMehta
9 views26 slides
Introduction to Maven by
Introduction to MavenIntroduction to Maven
Introduction to MavenJohn Valentino
6 views10 slides
360 graden fabriek by
360 graden fabriek360 graden fabriek
360 graden fabriekinfo33492
165 views25 slides
How Workforce Management Software Empowers SMEs | TraQSuite by
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteTraQSuite
6 views3 slides

Recently uploaded(20)

ADDO_2022_CICID_Tom_Halpin.pdf by TomHalpin9
ADDO_2022_CICID_Tom_Halpin.pdfADDO_2022_CICID_Tom_Halpin.pdf
ADDO_2022_CICID_Tom_Halpin.pdf
TomHalpin95 views
Electronic AWB - Electronic Air Waybill by Freightoscope
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill
Freightoscope 5 views
Airline Booking Software by SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta9 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info33492165 views
How Workforce Management Software Empowers SMEs | TraQSuite by TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite6 views
How to build dyanmic dashboards and ensure they always work by Wiiisdom
How to build dyanmic dashboards and ensure they always workHow to build dyanmic dashboards and ensure they always work
How to build dyanmic dashboards and ensure they always work
Wiiisdom14 views
Ports-and-Adapters Architecture for Embedded HMI by Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert33 views
Transport Management System - Shipment & Container Tracking by Freightoscope
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container Tracking
Freightoscope 5 views
Understanding HTML terminology by artembondar5
Understanding HTML terminologyUnderstanding HTML terminology
Understanding HTML terminology
artembondar57 views
Generic or specific? Making sensible software design decisions by Bert Jan Schrijver
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy15 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67025 views

Laravels IoC Container