SlideShare a Scribd company logo
1 of 52
Download to read offline
Inversion Of Control

@chadhietala
chadhietala.com
A Software Design Pattern
Invert the business logic
flow through some sort of
assembler
Dependency Inversion
A Software Design Principle
Depend on abstractions,
not concreations
Decouple your high level
parts of your system from
the low level parts by
using interfaces.
Don’t call us. We’ll Call You.
- Martin Fowler
So don’t do this...
function MyClass () {
this.multiply = new Multiplier();
}
Instead Inject
function MyClass () {
console.log(this.multiply); // Multiplier Instance
}
Reasons To Use
●
●
●
●

Gain maintainability
APIs are more elegant & abstract
Easy to test
Gain Modularity
But how?
A Couple Different
Approaches
Dependency Injection (DI)
&
IoC Containers
DI In The Wild

At least in the JavaScript World
Introspective DI

At least in the JavaScript World
Look At The Signature
Angular
var App = angular.module('App');
App.controller('PostController', function ( $scope, $http ) {
$scope.posts = [];

$http.get('/posts').then( function ( posts ) {
$scope.posts = posts;
});
});
Angular
var App = angular.module('App');
App.controller('PostController', function ( $scope, $http ) {
$scope.posts = [];

$http.get('/posts').then( function ( posts ) {
$scope.posts = posts;
});
});

Injected
Angular: Under The Hood
Non-injected Function
Module

●
●
●
●

App begins to parse the
HTML
Discovers any directives
Looks at what objects
those directives point to
Pass the un-injected
functions to the injector

Injector

●
●
●
●

Calls .toString on function
RegEx magic to check
what services to inject
Check registry
Creates instance with
injected items and
caches
Angular: Under The Hood
Non-injected Function
Module

●
●
●
●

App begins to parse the
HTML
Discovers any directives
Looks at what objects
those directives point to
Pass the un-injected
functions to the injector

Injector

Inverted Control

●
●
●
●

Calls .toString on function
RegEx magic to check
what services to inject
Check registry
Creates instance with
injected items and
caches
What About Mangling?
Angular Why U So Verbose?
angular.module('App', [ 'App.controllers' ]);

angular.module('App.controllers', [])
.controller( 'PostController', [ '$scope', '$http', function ( $scope, $http ) {
$scope.posts = [];

$http.get('/posts').then( function ( posts ) {
$scope.posts = posts;
});
}]);
Angular Why U So Verbose?
angular.module('App', [ 'App.controllers' ]);

angular.module('App.controllers', [])
.controller( 'PostController', [ '$scope', '$http', function ( $scope, $http ) {
$scope.posts = [];

$http.get('/posts').then( function ( posts ) {
$scope.posts = posts;
});
}]);

String representation of injections
$provider, $services, $values, & $factories
angular.module('App', ['App.factories', 'App.controllers']);

angular.module('App.factories', [])
.factory('$session', function(){
var key = 'dskjsadljs3423243432';
return {
getKey: function () {
return key;
}
};
});

angular.controller('App.controller', [])
.controller('PostsController', [ '$scope', '$session', function ( $scope,
$session ) {
$scope.session = $session.getKey() // dskjsadljs3423243432
}]);
IoC Containers

Not the official logo
The container owns everything
Kills The Boilerplate
Ember
App = Ember.Application.create();

App.PostsRoute = Ember.Route.extend({
model: function () {
return this.store.get('posts');
}
});
Ember
App = Ember.Application.create();

App.PostsRoute = Ember.Route.extend({
model: function () {
return this.store.get('posts');
}
});

Injected
Ember: Under The Hood
Container

Application

Initializers

●
●

Application creates container
Initializers register low-level
modules into the container
Ember: Under The Hood
●
Registry

●
●

Container

Injections
●
Lookup

Modules are registered into the
registry
Injections are held in a separate
map
Lookup checks to see if the
module is available and also if
the requested module needs to
be injected
Lookup then creates the
instance with the injections
Ember: Under The Hood
●
Registry

●
●

Container

Injections
●
Lookup

Modules are registered into the
registry
Injections are held in a separate
map
Lookup checks to see if the
module is available and also if
the requested module needs to
be injected
Lookup then creates the
instance with the injections
Inverted Control
Yo Dawg I Heard You
Liked Containers...
A Closer Look
var Session = Ember.Object.extend({
key: 'jkldsajlksldkjsjlad2312ekljk3'
});

var PostsController = Ember.Object.extend();
var PostController = Ember.Object.extend();

var container = new Ember.Container();

container.register('session:main', Session );
container.register('controller:posts', PostsController );
container.register('controller:post', PostController );
container.inject('controller', 'session', 'session:main');

var postController = container.lookup('controller:post');
postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
A Closer Look
var Session = Ember.Object.extend({
key: 'jkldsajlksldkjsjlad2312ekljk3'
});

var PostsController = Ember.Object.extend();
var PostController = Ember.Object.extend();

var container = new Ember.Container();

container.register('session:main', Session );
container.register('controller:posts', PostsController );
container.register('controller:post', PostController );
container.inject('controller', 'session', 'session:main');

All controllers
var postController = container.lookup('controller:post');
postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
A Closer Look
var Session = Ember.Object.extend({
key: 'jkldsajlksldkjsjlad2312ekljk3'
});

var PostsController = Ember.Object.extend();
var PostController = Ember.Object.extend();

var container = new Ember.Container();

container.register('session:main', Session );
container.register('controller:posts', PostsController );
container.register('controller:post', PostController );
container.inject('controller', 'session', 'session:main');

Add a property “session”
var postController = container.lookup('controller:post');
postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
A Closer Look
var Session = Ember.Object.extend({
key: 'jkldsajlksldkjsjlad2312ekljk3'
});

var PostsController = Ember.Object.extend();
var PostController = Ember.Object.extend();

var container = new Ember.Container();

container.register('session:main', Session );
container.register('controller:posts', PostsController );
container.register('controller:post', PostController );
container.inject('controller', 'session', 'session:main');
With the instance of ‘session:main’
var postController = container.lookup('controller:post');
postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
A Closer Look
var Session = Ember.Object.extend({
key: 'jkldsajlksldkjsjlad2312ekljk3'
});

var PostsController = Ember.Object.extend();
var PostController = Ember.Object.extend();

var container = new Ember.Container();

container.register('session:main', Session );
container.register('controller:posts', PostsController );
container.register('controller:post', PostController );
container.inject('controller', 'session', 'session:main');

var postController = container.lookup('controller:post');
postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
A Closer Look cont.
var postsController = container.lookup('controller:posts');
postsController.get('session.key') //
jkldsajlksldkjsjlad2312ekljk3

console.log( postsController.container ) // Points to container
console.log( postController.container ) // Points to container
console.log(
postController.container.lookup( 'controller:posts' )
) // Points to the same posts controller instance in memory
Ember’s Elegant APIs
App.PostController = Ember.Controller.extend({
// Fetches the comments controller and then sets
// this.controllers.comments to the comments instance
needs: ['comments']
});

App.PostRoute = Ember.Route.extend({
setupController: function(){
// Returns the comments instance
var comments = this.controllerFor('comments');
// Returns the comments model
var commentsModel = this.modelFor('comments');
}
});
But Doesn’t AMD Solve This?
I Would Say No
Dependency Loading &
Ordering
That isn’t IoC
AMD loaders are just simply
dependency managers
They sit outside of the
business domain.
AMD should not be your solution
for systemic lookup of objects
Don’t use it as a hammer because…
you will commit SRP violations
define( [ 'backbone', 'views/a_view', 'views/a_sub_view', 'helpers/time_formatter', 'helpers/date_formatter', 'helpers/tokenizer' ], function ( Aview, SubView,
Time, Date, Tokenizer ) {
return Backbone.View.extend({
initialize: function ( ) {
this.time = new Time();
this.date = new Date();
this.tokenizer = new Tokenizer();

this.render();
},
render: function () {
var renderBuffer = [];
this.collection.each( function (list) {
var item = new SubView({ model: list });
renderBuffer.push( item.render().el );
});
this.el.append( renderBuffer )
}
});
});
Summary
● Deal with abstractions
● Invert control and don’t deal with
concreations
● AMD is just a loading tool
Fin.

More Related Content

What's hot

Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptŁukasz Kużyński
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node jsThomas Roch
 
Taking Objective-C to the next level. UA Mobile 2016.
Taking Objective-C to the next level. UA Mobile 2016.Taking Objective-C to the next level. UA Mobile 2016.
Taking Objective-C to the next level. UA Mobile 2016.UA Mobile
 
[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutesGlobant
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jscacois
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?Anna Su
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptjnewmanux
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICKonstantin Kudryashov
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Paco de la Cruz
 
«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​FDConf
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.jsMatthew Beale
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needKacper Gunia
 

What's hot (20)

Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
Rxjs vienna
Rxjs viennaRxjs vienna
Rxjs vienna
 
Nevermore Unit Testing
Nevermore Unit TestingNevermore Unit Testing
Nevermore Unit Testing
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
 
JavaScript Promise
JavaScript PromiseJavaScript Promise
JavaScript Promise
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node js
 
Min-Maxing Software Costs
Min-Maxing Software CostsMin-Maxing Software Costs
Min-Maxing Software Costs
 
Taking Objective-C to the next level. UA Mobile 2016.
Taking Objective-C to the next level. UA Mobile 2016.Taking Objective-C to the next level. UA Mobile 2016.
Taking Objective-C to the next level. UA Mobile 2016.
 
[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
 
NestJS
NestJSNestJS
NestJS
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30)
 
«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​
 
Zend framework service
Zend framework serviceZend framework service
Zend framework service
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.js
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 

Viewers also liked

meet knowledge management, by alexis valourdos
meet knowledge management, by alexis valourdos meet knowledge management, by alexis valourdos
meet knowledge management, by alexis valourdos ALEXBALOO
 
Diagrammatic knowledge modeling for managers – ontology-based approach
Diagrammatic knowledge modeling for managers  – ontology-based approachDiagrammatic knowledge modeling for managers  – ontology-based approach
Diagrammatic knowledge modeling for managers – ontology-based approachDmitry Kudryavtsev
 
Federal Knowledge Management Initiative Roadmap
Federal Knowledge Management Initiative RoadmapFederal Knowledge Management Initiative Roadmap
Federal Knowledge Management Initiative Roadmapdowntown76
 
Knowledge Management Program in the Canadian Forest Service
Knowledge Management Program in the Canadian Forest ServiceKnowledge Management Program in the Canadian Forest Service
Knowledge Management Program in the Canadian Forest ServiceAlbert Simard
 
Онтологии и информационная архитектура: соотношение терминов и потенциал совм...
Онтологии и информационная архитектура: соотношение терминов и потенциал совм...Онтологии и информационная архитектура: соотношение терминов и потенциал совм...
Онтологии и информационная архитектура: соотношение терминов и потенциал совм...Dmitry Kudryavtsev
 
Collaborative Knowledge Management in Organization from SECI model Framework
Collaborative Knowledge Management in Organization from SECI model FrameworkCollaborative Knowledge Management in Organization from SECI model Framework
Collaborative Knowledge Management in Organization from SECI model FrameworkNatapone Charsombut
 
Global knowledge management_pawlowski_2012
Global knowledge management_pawlowski_2012Global knowledge management_pawlowski_2012
Global knowledge management_pawlowski_2012Jan Pawlowski
 
Performance of Knowledge Management
Performance of Knowledge ManagementPerformance of Knowledge Management
Performance of Knowledge ManagementElijah Ezendu
 
Knowledge Management and Artificial Intelligence
Knowledge Management and Artificial IntelligenceKnowledge Management and Artificial Intelligence
Knowledge Management and Artificial IntelligenceAndrejkovics Zoltán
 
A brief introduction to Knowledge Management
A brief introduction to Knowledge ManagementA brief introduction to Knowledge Management
A brief introduction to Knowledge ManagementMartyn Richard Jones
 
Market Research and Knowledge Management
Market Research and Knowledge ManagementMarket Research and Knowledge Management
Market Research and Knowledge Managementrotciv
 
knowledge management tools
knowledge management toolsknowledge management tools
knowledge management toolsAbin Biju
 
IT Infrastructure & Knowledge Management in CAs Office
IT Infrastructure & Knowledge Management in CAs OfficeIT Infrastructure & Knowledge Management in CAs Office
IT Infrastructure & Knowledge Management in CAs OfficeCA. B.C. Chechani
 
Why people don't share their knowledge
Why people don't share their knowledgeWhy people don't share their knowledge
Why people don't share their knowledgeStan Garfield
 
Knowledge Management Chapter 1
Knowledge Management   Chapter 1Knowledge Management   Chapter 1
Knowledge Management Chapter 1NISHA SHAH
 
Storytelling & Knowledge Management
Storytelling & Knowledge ManagementStorytelling & Knowledge Management
Storytelling & Knowledge ManagementEric Brown
 
Knowledge management (KM) tools
Knowledge management (KM) toolsKnowledge management (KM) tools
Knowledge management (KM) toolsDmitry Kudryavtsev
 
Knowledge management
Knowledge managementKnowledge management
Knowledge managementAbdullah Rady
 

Viewers also liked (20)

meet knowledge management, by alexis valourdos
meet knowledge management, by alexis valourdos meet knowledge management, by alexis valourdos
meet knowledge management, by alexis valourdos
 
Diagrammatic knowledge modeling for managers – ontology-based approach
Diagrammatic knowledge modeling for managers  – ontology-based approachDiagrammatic knowledge modeling for managers  – ontology-based approach
Diagrammatic knowledge modeling for managers – ontology-based approach
 
Federal Knowledge Management Initiative Roadmap
Federal Knowledge Management Initiative RoadmapFederal Knowledge Management Initiative Roadmap
Federal Knowledge Management Initiative Roadmap
 
08 sessions content
08 sessions content08 sessions content
08 sessions content
 
Knowledge Management Program in the Canadian Forest Service
Knowledge Management Program in the Canadian Forest ServiceKnowledge Management Program in the Canadian Forest Service
Knowledge Management Program in the Canadian Forest Service
 
Онтологии и информационная архитектура: соотношение терминов и потенциал совм...
Онтологии и информационная архитектура: соотношение терминов и потенциал совм...Онтологии и информационная архитектура: соотношение терминов и потенциал совм...
Онтологии и информационная архитектура: соотношение терминов и потенциал совм...
 
New Approaches to Knowledge Management (part 1)
New Approaches to Knowledge Management (part 1)New Approaches to Knowledge Management (part 1)
New Approaches to Knowledge Management (part 1)
 
Collaborative Knowledge Management in Organization from SECI model Framework
Collaborative Knowledge Management in Organization from SECI model FrameworkCollaborative Knowledge Management in Organization from SECI model Framework
Collaborative Knowledge Management in Organization from SECI model Framework
 
Global knowledge management_pawlowski_2012
Global knowledge management_pawlowski_2012Global knowledge management_pawlowski_2012
Global knowledge management_pawlowski_2012
 
Performance of Knowledge Management
Performance of Knowledge ManagementPerformance of Knowledge Management
Performance of Knowledge Management
 
Knowledge Management and Artificial Intelligence
Knowledge Management and Artificial IntelligenceKnowledge Management and Artificial Intelligence
Knowledge Management and Artificial Intelligence
 
A brief introduction to Knowledge Management
A brief introduction to Knowledge ManagementA brief introduction to Knowledge Management
A brief introduction to Knowledge Management
 
Market Research and Knowledge Management
Market Research and Knowledge ManagementMarket Research and Knowledge Management
Market Research and Knowledge Management
 
knowledge management tools
knowledge management toolsknowledge management tools
knowledge management tools
 
IT Infrastructure & Knowledge Management in CAs Office
IT Infrastructure & Knowledge Management in CAs OfficeIT Infrastructure & Knowledge Management in CAs Office
IT Infrastructure & Knowledge Management in CAs Office
 
Why people don't share their knowledge
Why people don't share their knowledgeWhy people don't share their knowledge
Why people don't share their knowledge
 
Knowledge Management Chapter 1
Knowledge Management   Chapter 1Knowledge Management   Chapter 1
Knowledge Management Chapter 1
 
Storytelling & Knowledge Management
Storytelling & Knowledge ManagementStorytelling & Knowledge Management
Storytelling & Knowledge Management
 
Knowledge management (KM) tools
Knowledge management (KM) toolsKnowledge management (KM) tools
Knowledge management (KM) tools
 
Knowledge management
Knowledge managementKnowledge management
Knowledge management
 

Similar to Inversion Of Control

The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade ServerlessKatyShimizu
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade ServerlessKatyShimizu
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Paco de la Cruz
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Paco de la Cruz
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationDan Wahlin
 
Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive AppsJorge Ortiz
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravelwajrcs
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonfNataliya Patsovska
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4Naga Muruga
 
ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in PracticeOutware Mobile
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 

Similar to Inversion Of Control (20)

The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
AngularJs
AngularJsAngularJs
AngularJs
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
 
Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive Apps
 
Side effects-con-redux
Side effects-con-reduxSide effects-con-redux
Side effects-con-redux
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravel
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4
 
ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in Practice
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 

Recently uploaded

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Inversion Of Control

  • 3. Invert the business logic flow through some sort of assembler
  • 5. A Software Design Principle
  • 7. Decouple your high level parts of your system from the low level parts by using interfaces.
  • 8. Don’t call us. We’ll Call You. - Martin Fowler
  • 9. So don’t do this... function MyClass () { this.multiply = new Multiplier(); }
  • 10. Instead Inject function MyClass () { console.log(this.multiply); // Multiplier Instance }
  • 11. Reasons To Use ● ● ● ● Gain maintainability APIs are more elegant & abstract Easy to test Gain Modularity
  • 15. DI In The Wild At least in the JavaScript World
  • 16. Introspective DI At least in the JavaScript World
  • 17. Look At The Signature
  • 18. Angular var App = angular.module('App'); App.controller('PostController', function ( $scope, $http ) { $scope.posts = []; $http.get('/posts').then( function ( posts ) { $scope.posts = posts; }); });
  • 19. Angular var App = angular.module('App'); App.controller('PostController', function ( $scope, $http ) { $scope.posts = []; $http.get('/posts').then( function ( posts ) { $scope.posts = posts; }); }); Injected
  • 20. Angular: Under The Hood Non-injected Function Module ● ● ● ● App begins to parse the HTML Discovers any directives Looks at what objects those directives point to Pass the un-injected functions to the injector Injector ● ● ● ● Calls .toString on function RegEx magic to check what services to inject Check registry Creates instance with injected items and caches
  • 21. Angular: Under The Hood Non-injected Function Module ● ● ● ● App begins to parse the HTML Discovers any directives Looks at what objects those directives point to Pass the un-injected functions to the injector Injector Inverted Control ● ● ● ● Calls .toString on function RegEx magic to check what services to inject Check registry Creates instance with injected items and caches
  • 23. Angular Why U So Verbose? angular.module('App', [ 'App.controllers' ]); angular.module('App.controllers', []) .controller( 'PostController', [ '$scope', '$http', function ( $scope, $http ) { $scope.posts = []; $http.get('/posts').then( function ( posts ) { $scope.posts = posts; }); }]);
  • 24. Angular Why U So Verbose? angular.module('App', [ 'App.controllers' ]); angular.module('App.controllers', []) .controller( 'PostController', [ '$scope', '$http', function ( $scope, $http ) { $scope.posts = []; $http.get('/posts').then( function ( posts ) { $scope.posts = posts; }); }]); String representation of injections
  • 25. $provider, $services, $values, & $factories angular.module('App', ['App.factories', 'App.controllers']); angular.module('App.factories', []) .factory('$session', function(){ var key = 'dskjsadljs3423243432'; return { getKey: function () { return key; } }; }); angular.controller('App.controller', []) .controller('PostsController', [ '$scope', '$session', function ( $scope, $session ) { $scope.session = $session.getKey() // dskjsadljs3423243432 }]);
  • 26. IoC Containers Not the official logo
  • 27. The container owns everything
  • 29. Ember App = Ember.Application.create(); App.PostsRoute = Ember.Route.extend({ model: function () { return this.store.get('posts'); } });
  • 30. Ember App = Ember.Application.create(); App.PostsRoute = Ember.Route.extend({ model: function () { return this.store.get('posts'); } }); Injected
  • 31. Ember: Under The Hood Container Application Initializers ● ● Application creates container Initializers register low-level modules into the container
  • 32. Ember: Under The Hood ● Registry ● ● Container Injections ● Lookup Modules are registered into the registry Injections are held in a separate map Lookup checks to see if the module is available and also if the requested module needs to be injected Lookup then creates the instance with the injections
  • 33. Ember: Under The Hood ● Registry ● ● Container Injections ● Lookup Modules are registered into the registry Injections are held in a separate map Lookup checks to see if the module is available and also if the requested module needs to be injected Lookup then creates the instance with the injections Inverted Control
  • 34. Yo Dawg I Heard You Liked Containers...
  • 35. A Closer Look var Session = Ember.Object.extend({ key: 'jkldsajlksldkjsjlad2312ekljk3' }); var PostsController = Ember.Object.extend(); var PostController = Ember.Object.extend(); var container = new Ember.Container(); container.register('session:main', Session ); container.register('controller:posts', PostsController ); container.register('controller:post', PostController ); container.inject('controller', 'session', 'session:main'); var postController = container.lookup('controller:post'); postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
  • 36. A Closer Look var Session = Ember.Object.extend({ key: 'jkldsajlksldkjsjlad2312ekljk3' }); var PostsController = Ember.Object.extend(); var PostController = Ember.Object.extend(); var container = new Ember.Container(); container.register('session:main', Session ); container.register('controller:posts', PostsController ); container.register('controller:post', PostController ); container.inject('controller', 'session', 'session:main'); All controllers var postController = container.lookup('controller:post'); postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
  • 37. A Closer Look var Session = Ember.Object.extend({ key: 'jkldsajlksldkjsjlad2312ekljk3' }); var PostsController = Ember.Object.extend(); var PostController = Ember.Object.extend(); var container = new Ember.Container(); container.register('session:main', Session ); container.register('controller:posts', PostsController ); container.register('controller:post', PostController ); container.inject('controller', 'session', 'session:main'); Add a property “session” var postController = container.lookup('controller:post'); postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
  • 38. A Closer Look var Session = Ember.Object.extend({ key: 'jkldsajlksldkjsjlad2312ekljk3' }); var PostsController = Ember.Object.extend(); var PostController = Ember.Object.extend(); var container = new Ember.Container(); container.register('session:main', Session ); container.register('controller:posts', PostsController ); container.register('controller:post', PostController ); container.inject('controller', 'session', 'session:main'); With the instance of ‘session:main’ var postController = container.lookup('controller:post'); postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
  • 39. A Closer Look var Session = Ember.Object.extend({ key: 'jkldsajlksldkjsjlad2312ekljk3' }); var PostsController = Ember.Object.extend(); var PostController = Ember.Object.extend(); var container = new Ember.Container(); container.register('session:main', Session ); container.register('controller:posts', PostsController ); container.register('controller:post', PostController ); container.inject('controller', 'session', 'session:main'); var postController = container.lookup('controller:post'); postController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3
  • 40. A Closer Look cont. var postsController = container.lookup('controller:posts'); postsController.get('session.key') // jkldsajlksldkjsjlad2312ekljk3 console.log( postsController.container ) // Points to container console.log( postController.container ) // Points to container console.log( postController.container.lookup( 'controller:posts' ) ) // Points to the same posts controller instance in memory
  • 41. Ember’s Elegant APIs App.PostController = Ember.Controller.extend({ // Fetches the comments controller and then sets // this.controllers.comments to the comments instance needs: ['comments'] }); App.PostRoute = Ember.Route.extend({ setupController: function(){ // Returns the comments instance var comments = this.controllerFor('comments'); // Returns the comments model var commentsModel = this.modelFor('comments'); } });
  • 42. But Doesn’t AMD Solve This?
  • 46. AMD loaders are just simply dependency managers
  • 47. They sit outside of the business domain.
  • 48. AMD should not be your solution for systemic lookup of objects
  • 49. Don’t use it as a hammer because…
  • 50. you will commit SRP violations define( [ 'backbone', 'views/a_view', 'views/a_sub_view', 'helpers/time_formatter', 'helpers/date_formatter', 'helpers/tokenizer' ], function ( Aview, SubView, Time, Date, Tokenizer ) { return Backbone.View.extend({ initialize: function ( ) { this.time = new Time(); this.date = new Date(); this.tokenizer = new Tokenizer(); this.render(); }, render: function () { var renderBuffer = []; this.collection.each( function (list) { var item = new SubView({ model: list }); renderBuffer.push( item.render().el ); }); this.el.append( renderBuffer ) } }); });
  • 51. Summary ● Deal with abstractions ● Invert control and don’t deal with concreations ● AMD is just a loading tool
  • 52. Fin.