SlideShare a Scribd company logo
NodeJS Spring style Inversifyjs
FAIT MOI RÊVERFAIT MOI RÊVER
DI, Ioc, Kamouloxx ?
 
Inversify
 
Demo
DEPENDENCY INJECTIONDEPENDENCY INJECTION
AKA : DIAKA : DI
DI : WHY ?DI : WHY ?
Lets imagine two classes A and B. A is using B :
A B
class A {
constructor (){
this.b = new B(SECRET_KEY);
}
}
No Factorisation
Untestable
Strongly coupled
Bad separation of concerns
DI : WHAT ?DI : WHAT ?
The fifth of  principles in
OOP. Dependencies should be
given.
SOLID
class A {
constructor (private b:B){ }
}
A BC
import A from './A';
import B from './B';
const b = new B();
const a = new A(b);
// ...
const anotherService = new D(b);
DI : WHAT ?DI : WHAT ?
Easy to test :
describe('Class A', () => {
it('should behaves as expected', ()=> {
// given
const mockOfB = {
fakeMethod() {
/* do something */
}
};
const a = new A (mockOfB);
// when -> then ...
});
});
INJECTION OF CONTROLINJECTION OF CONTROL
AKA : IOCAKA : IOC
IOC : WHY ?IOC : WHY ?
DI, is good, but give the dependencies at all is boring !
import UserService from '../service/user-service';
import SlackService from '../service/slack/slack-service';
import TenKiloService from '../service/ten-kilo/ten-kilo';
import axios from 'axios';
import bluebird from 'bluebird';
const userService = new UserService(
new SlackService(axios),
new TenKiloService(axios),
bluebird
);
IOC : WHAT ?IOC : WHAT ?
IOC is a design pattern, used to dissociate elements in OOP and
give an elegant way to build these elements.
A BC
Lightweight container
IOC : WHAT ?IOC : WHAT ?
IOC is a design pattern, used to dissociate elements in OOP and
give an elegant way to build these elements.
A BC
Lightweight container
IOC : WHAT ?IOC : WHAT ?
IOC is a design pattern, used to dissociate elements in OOP and
give an elegant way to build these elements.
A BC
Lightweight containerResponsible of
elements building &
connect them
IOC : SPRING, THE IOC FRAMEWORK FOR JAVAIOC : SPRING, THE IOC FRAMEWORK FOR JAVA
@Controller
class VetController {
private final VetRepository vets;
@Autowired
public VetController(VetRepository clinicService) {
this.vets = clinicService;
}
@RequestMapping(value = { "/vets.html" })
public String showVetList(Map<String, Object> model) {
Vets vets = new Vets();
vets.getVetList().addAll(this.vets.findAll());
model.put("vets", vets);
return "vets/vetList";
}
@RequestMapping(value = { "/vets.json", "/vets.xml" })
public @ResponseBody Vets showResourcesVetList() {
Vets vets = new Vets();
vets.getVetList().addAll(this.vets.findAll());
return vets;
}
}
SO, IOC IN JAVASCRIPT ?SO, IOC IN JAVASCRIPT ?
INVERSIFYJSINVERSIFYJS
INVERSIFYJSINVERSIFYJS
A powerful and lightweight inversion of control container
for JavaScript & Node.js apps powered by TypeScript.
INVERSIFYJSINVERSIFYJS
A powerful and lightweight inversion of control container
for JavaScript & Node.js apps powered by TypeScript.
Powered by TypeScript ???
INVERSIFYJSINVERSIFYJS
Why TypeScript ?
How a container know who depends of who ?
class A {
constructor (b) {
this.b = b;
}
}
'b' is just a parameter name. So, how to know to build it ?
someModule.controller('MyController', ['$scope', 'dep1', function($scope, dep1) {
...
$scope.aMethod = function() {
...
}
}]);
In AngularJS, the names was 'injection keys'
DEMODEMO
PHOENIX-APIPHOENIX-API
CONCLUSIONCONCLUSION
 
It's cool, but is it really useful in
JavaScript ?
 
Mock a dependency is easy in
NodeJS
 
DI why not, but IOC it's maybe
too much
import { Dependencies, Controller, RequestMapping, RequestMethod } from 'nest.js';
@Controller({ path: 'users' })
@Dependencies([ UsersService ])
export class UsersController {
constructor(usersService) {
this.usersService = usersService;
}
@Get()
getAllUsers(req, res, next) {
this.usersService.getAllUsers().then(users => res.status(200).json(users));
}
@Get('/:id')
getUser(req, res, next) {
this.usersService.getUser(+req.params.id).then(user => res.status(200).json(user));
}
@Post()
addUser(req, res, next) {
this.usersService.addUser(req.body.user).then(msg => res.status(201).json(msg));
}
}
ONE MORE THINGONE MORE THING
Spring & Spring MVC  in Node.JS !
@MatBreton
//goo.gl/37yIcf
Thank you

More Related Content

PDF
Class 6 2ciclo
PPTX
4front en
PDF
Kotlinでテストコードを書く
PDF
Unit Testing in Kotlin
PPT
PPTX
Advanced JavaScript Concepts
PPTX
Types of Constructor in C++
PDF
Cocoa heads 09112017
Class 6 2ciclo
4front en
Kotlinでテストコードを書く
Unit Testing in Kotlin
Advanced JavaScript Concepts
Types of Constructor in C++
Cocoa heads 09112017

What's hot (19)

PPTX
Java script
PPTX
Reactive Programming on Android - RxAndroid - RxJava
PPTX
OPERATING OVERLOADING IN VHDL
DOCX
Formal methods Project Report for the support of slides uploaded
PDF
Swift で JavaScript 始めませんか? #iOSDC
PDF
Advanced functional programing in Swift
PPTX
LinkedIn TBC JavaScript 100: Functions
PDF
Monads in Swift
PDF
JavaOne 2013: Java 8 - The Good Parts
PDF
Introduction to RxJS
PPTX
Boxing & unboxing
PPTX
Introduction to RxJava on Android
PPTX
Code craftsmanship saturdays second session
PDF
RxJava for Android - GDG DevFest Ukraine 2015
PPT
Swiss army knife Spring
PDF
JavaScript Functions
PPTX
DOC
Procedure to create_the_calculator_application java
PDF
Protocol-Oriented Programming in Swift
Java script
Reactive Programming on Android - RxAndroid - RxJava
OPERATING OVERLOADING IN VHDL
Formal methods Project Report for the support of slides uploaded
Swift で JavaScript 始めませんか? #iOSDC
Advanced functional programing in Swift
LinkedIn TBC JavaScript 100: Functions
Monads in Swift
JavaOne 2013: Java 8 - The Good Parts
Introduction to RxJS
Boxing & unboxing
Introduction to RxJava on Android
Code craftsmanship saturdays second session
RxJava for Android - GDG DevFest Ukraine 2015
Swiss army knife Spring
JavaScript Functions
Procedure to create_the_calculator_application java
Protocol-Oriented Programming in Swift
Ad

Similar to NodeJS Spring style Inversifyjs (20)

PPTX
Dependency Injection and Inversion of Control .pptx
PPT
The Prana IoC Container
PPTX
Dip(dependency inversion principle) presentation
PPTX
Dependency Injection in .NET
PPTX
Dependency Inversion Principle
PPTX
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
PPTX
Dependency injection
PDF
Dependency Injection
PPTX
Brownbag001 spring ioc from 2012
PPT
Spring ActionScript
PPTX
Clearing confusion about IoC (Inversion of Control)
PDF
Slaying Sacred Cows: Deconstructing Dependency Injection
PPTX
Oleksandr Valetskyy - DI vs. IoC
PPTX
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
PDF
Short story about DI in JS
PDF
Parsley & Flex
PPTX
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
PPTX
Polaris presentation ioc - code conference
PPT
Spring overview &amp; architecture
PPTX
IoC and Dependency Injection
Dependency Injection and Inversion of Control .pptx
The Prana IoC Container
Dip(dependency inversion principle) presentation
Dependency Injection in .NET
Dependency Inversion Principle
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Dependency injection
Dependency Injection
Brownbag001 spring ioc from 2012
Spring ActionScript
Clearing confusion about IoC (Inversion of Control)
Slaying Sacred Cows: Deconstructing Dependency Injection
Oleksandr Valetskyy - DI vs. IoC
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Short story about DI in JS
Parsley & Flex
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Polaris presentation ioc - code conference
Spring overview &amp; architecture
IoC and Dependency Injection
Ad

More from Mathieu Breton (8)

PDF
TDD in Javascript
PDF
Meet VueJs
PDF
FalcorJS
PDF
BDD in Javascript
PDF
Clean code in JavaScript
PDF
Rollup.js
PDF
Présentation de Dart
PDF
JavaScript the-next-big...bytecode
TDD in Javascript
Meet VueJs
FalcorJS
BDD in Javascript
Clean code in JavaScript
Rollup.js
Présentation de Dart
JavaScript the-next-big...bytecode

Recently uploaded (20)

PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Getting Started with Data Integration: FME Form 101
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mushroom cultivation and it's methods.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
Univ-Connecticut-ChatGPT-Presentaion.pdf
A comparative study of natural language inference in Swahili using monolingua...
Reach Out and Touch Someone: Haptics and Empathic Computing
gpt5_lecture_notes_comprehensive_20250812015547.pdf
A Presentation on Artificial Intelligence
Mobile App Security Testing_ A Comprehensive Guide.pdf
Heart disease approach using modified random forest and particle swarm optimi...
Getting Started with Data Integration: FME Form 101
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
SOPHOS-XG Firewall Administrator PPT.pptx
Tartificialntelligence_presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mushroom cultivation and it's methods.pdf
Empathic Computing: Creating Shared Understanding
TLE Review Electricity (Electricity).pptx
Programs and apps: productivity, graphics, security and other tools

NodeJS Spring style Inversifyjs

  • 2. FAIT MOI RÊVERFAIT MOI RÊVER DI, Ioc, Kamouloxx ?   Inversify   Demo
  • 4. DI : WHY ?DI : WHY ? Lets imagine two classes A and B. A is using B : A B class A { constructor (){ this.b = new B(SECRET_KEY); } } No Factorisation Untestable Strongly coupled Bad separation of concerns
  • 5. DI : WHAT ?DI : WHAT ? The fifth of  principles in OOP. Dependencies should be given. SOLID class A { constructor (private b:B){ } } A BC import A from './A'; import B from './B'; const b = new B(); const a = new A(b); // ... const anotherService = new D(b);
  • 6. DI : WHAT ?DI : WHAT ? Easy to test : describe('Class A', () => { it('should behaves as expected', ()=> { // given const mockOfB = { fakeMethod() { /* do something */ } }; const a = new A (mockOfB); // when -> then ... }); });
  • 7. INJECTION OF CONTROLINJECTION OF CONTROL AKA : IOCAKA : IOC
  • 8. IOC : WHY ?IOC : WHY ? DI, is good, but give the dependencies at all is boring ! import UserService from '../service/user-service'; import SlackService from '../service/slack/slack-service'; import TenKiloService from '../service/ten-kilo/ten-kilo'; import axios from 'axios'; import bluebird from 'bluebird'; const userService = new UserService( new SlackService(axios), new TenKiloService(axios), bluebird );
  • 9. IOC : WHAT ?IOC : WHAT ? IOC is a design pattern, used to dissociate elements in OOP and give an elegant way to build these elements. A BC Lightweight container
  • 10. IOC : WHAT ?IOC : WHAT ? IOC is a design pattern, used to dissociate elements in OOP and give an elegant way to build these elements. A BC Lightweight container
  • 11. IOC : WHAT ?IOC : WHAT ? IOC is a design pattern, used to dissociate elements in OOP and give an elegant way to build these elements. A BC Lightweight containerResponsible of elements building & connect them
  • 12. IOC : SPRING, THE IOC FRAMEWORK FOR JAVAIOC : SPRING, THE IOC FRAMEWORK FOR JAVA @Controller class VetController { private final VetRepository vets; @Autowired public VetController(VetRepository clinicService) { this.vets = clinicService; } @RequestMapping(value = { "/vets.html" }) public String showVetList(Map<String, Object> model) { Vets vets = new Vets(); vets.getVetList().addAll(this.vets.findAll()); model.put("vets", vets); return "vets/vetList"; } @RequestMapping(value = { "/vets.json", "/vets.xml" }) public @ResponseBody Vets showResourcesVetList() { Vets vets = new Vets(); vets.getVetList().addAll(this.vets.findAll()); return vets; } }
  • 13. SO, IOC IN JAVASCRIPT ?SO, IOC IN JAVASCRIPT ?
  • 15. INVERSIFYJSINVERSIFYJS A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
  • 16. INVERSIFYJSINVERSIFYJS A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript. Powered by TypeScript ???
  • 17. INVERSIFYJSINVERSIFYJS Why TypeScript ? How a container know who depends of who ? class A { constructor (b) { this.b = b; } } 'b' is just a parameter name. So, how to know to build it ? someModule.controller('MyController', ['$scope', 'dep1', function($scope, dep1) { ... $scope.aMethod = function() { ... } }]); In AngularJS, the names was 'injection keys'
  • 19. CONCLUSIONCONCLUSION   It's cool, but is it really useful in JavaScript ?   Mock a dependency is easy in NodeJS   DI why not, but IOC it's maybe too much
  • 20. import { Dependencies, Controller, RequestMapping, RequestMethod } from 'nest.js'; @Controller({ path: 'users' }) @Dependencies([ UsersService ]) export class UsersController { constructor(usersService) { this.usersService = usersService; } @Get() getAllUsers(req, res, next) { this.usersService.getAllUsers().then(users => res.status(200).json(users)); } @Get('/:id') getUser(req, res, next) { this.usersService.getUser(+req.params.id).then(user => res.status(200).json(user)); } @Post() addUser(req, res, next) { this.usersService.addUser(req.body.user).then(msg => res.status(201).json(msg)); } } ONE MORE THINGONE MORE THING Spring & Spring MVC  in Node.JS !