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] 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
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] 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] 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
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] 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

Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

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.