Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Angular DI Processor Pattern
Search
Jecelyn Yeen
September 27, 2018
Programming
0
980
Angular DI Processor Pattern
Implement Processor Pattern with Angular Dependency Injection
Jecelyn Yeen
September 27, 2018
Tweet
Share
More Decks by Jecelyn Yeen
See All by Jecelyn Yeen
WorkerConf 2021 - Browser automation with Puppeteer
jecfish
0
1.6k
My Journey as Technical Presenter
jecfish
0
840
Becoming a GDE
jecfish
0
3.6k
How to get started in IT Freelancing
jecfish
1
260
New Web API & Stylings
jecfish
3
630
如何打造高性能且SEO友好的单页应用(SPA)
jecfish
2
730
JS SEO
jecfish
4
1.4k
Web Performance Optimization
jecfish
5
1.7k
Have Fun with Angular
jecfish
0
89
Other Decks in Programming
See All in Programming
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
200
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
300
Quine, Polyglot, 良いコード
qnighy
4
630
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
390
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
110
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
300
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
200
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
280
Realtime API 入門
riofujimon
0
140
macOS でできる リアルタイム動画像処理
biacco42
9
2.3k
Macとオーディオ再生 2024/11/02
yusukeito
0
340
Identifying User Idenity
moro
6
9.6k
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Agile that works and the tools we love
rasmusluckow
327
21k
Facilitating Awesome Meetings
lara
50
6.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
505
140k
Producing Creativity
orderedlist
PRO
341
39k
Bash Introduction
62gerente
608
210k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Writing Fast Ruby
sferik
627
61k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
Transcript
Angular | Dependency Injection | Processor Pattern + +
@JecelynYeen From Kuala Lumpur, Malaysia • GDE - Web technologies,
Angular • Software Architect @ Randstad Organizer:
• Dependency Injection (DI) • DI in Angular • Processor
Pattern • DI + Processor Pattern in Angular + +
Dependency Injection . What & Why?
Weapon is made of material (wood). Ninja needs a weapon
(nunchakus). We have a ninja.
- Single Responsibility - Tightly coupled - Hard to unit
test
Dependency Injection
Hookup implementation during bootstrap inject in constructor no need to
instantiate
Replace implementation under the hood
Dependency Injection • Unit testable • Reusability • Loosely coupled
• Dependency Inversion principle
DI in Angular
service service hook up
• UseClass • UseValue • UseFactory • UseExisting + https://offering.solutions/blog/articles/2018/08/17/using-useclass-usefactory-usevalue-
useexisting-with-treeshakable-providers-in-angular/ https://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html
Dependency Injection is static
Dependency Injection is static hook up only once
what if our ninja need to switch weapon dynamically https://di-processor.firebaseapp.com/ninja-di
what if our ninja need to switch weapon dynamically https://di-processor.firebaseapp.com/ninja-di
nunchakus, dart, stick, sword
Processor Pattern using injection token & multi-provider
weapon interface name, draw(), animate() Inject into NinjaComponent as weapon[
] injection token processors multi-providers
Injection Token + Processor Interface
Processor implement the interface
Multiple providers with same token one token multiple implementations set
as multi
Inject multiple providers Injection 4 processors get one processor Invoke
processor functions
Production Use Case: Chart Processors
- chart type - title / menu - processing logic
- labels & tooltips Differences - they are all charts - same interface:- - processData() - name, title, etc Similar https://di-processor.firebaseapp.com
YYYY-MM what users want to see YYYY-MM-DD what backend returns
Frontend developer
what your chart library wants what you need to do
• transform data (loop & group it by year month) • sort it • generate chart configuration
What you actually do - Chart Processor https://github.com/chybie/di-processor/blob/master/src/app/chart-di/services/chart-new-starter-processor.service.ts private
Injection Token + Processor Interface
Multiple providers with same token
Dashboard Component
Other useful scenario • Data table processors • Search processors
https://stackoverflow.com/questions/48382323/angular-lookup-all- providers-implementing-a-specific-interface/ 48383858#comment83773434_48383858
Benefits • Abstraction • Plugins
slides: https://speakerdeck.com/chybie/angular-di-processor-pattern demo: https://di-processor.firebaseapp.com code: https://github.com/chybie/di-processor code (inject by service):
https://stackblitz.com/edit/ninja-weapon- processors?file=src%2Fapp%2Fninja%2Fninja.component.ts twitter: @JecelynYeen + +