dependency injection frameworky

Download Dependency Injection Frameworky

Post on 25-May-2015

2.578 views

Category:

Technology

1 download

Embed Size (px)

DESCRIPTION

Prezentace na tema Dependency inejction frameworky v Jave.

TRANSCRIPT

  • 1.

2. Dependency Injection frameworky v Jave
Dagi,
even, 2009
3. 3
24 June 2009
Agenda
1. Intro
2. Inversionofcontrol
3. Co by ml DI framework zvldnout
4. Srovnn vybranch DI framework
5. Q&A
4. Intro
5. 5
6/24/2009
For internal use only -- not for distribution
6. Martin Fowler
Refactoring
Continuousintegration
InversionofControl
6
6/24/2009
For internal use only -- not for distribution
7. Timeline
7
24 June 2009
http://www.picocontainer.org/inversion-of-control-history.html
8. InversionofControl
9. Programy ped zavedenm IoC
9
6/24/2009
For internal use only -- not for distribution
10. Programy po zaveden IoC
10
24 June 2009
11. Komponenty a jejich vazby
11
24 June 2009
12. 12
24 June 2009
public classReservationService {
privateBookServicebookService;
public ReservationService() {
init();
}
privatevoidinit () {
LocalBookStorelocalBookStore = newLocalBookStore();
localBookStore.setPath("/home/johndoe/data.xml");
setBookService(localBookStore);
}
public booleanreserveBook(longbookId, Datefrom,Date to,User u) {
Bookbook = bookService.getBook(bookId);
//kod vlastn rezervace vynechan
}
publicvoidsetBookService(BookServicebookService) {this.bookService=bookService;
}
}
13. KnowYourEnemy
13
24 June 2009
privatevoidinit () {
LocalBookStorelocalBookStore = newLocalBookStore();
localBookStore.setPath("/home/johndoe/data.xml");
setBookService(localBookStore);
}
14. Generalizace problmu
Kde najt
Jak zskat
Jak zkonfigurovat
Jak spojit dohromady
14
24 June 2009
15. Obrcen kontrola
vychz zprincipu penesen odpovdnosti za nalezen, konfiguraci a spojen komponent dohromady na nkoho tetho
Indirekce == voln vazby (looselycoupled)
Znovupouitelnost
Lep testovatelnost
Extenzibilita
Dv mon implementace
Pm zvislosti na prostednkovi
Nepm zvislosti na prostednkovi
15
24 June 2009
16. Servicelocator
16
24 June 2009
17. DependencyInjection
17
24 June 2009
18. Servicelocator vs. DI
Preferujte DI
dn tsn vazby
Transparentn
No singletonhell
Servicelocator
body napojen
Servlet
Controller aplikace
18
24 June 2009
19. Co by ml DI framework zvldnout
20. Minimln mon mra invaze
Invazivnost
Jak moc je jet komponenta POJO
Co je invazivn
Implementace rozhran
Odvozen komponenty od specifick tdy frameworku
Nemonost pouvat zkladn programov konstrukty
finln tdy
konstruktory s parametrem
Pro
Nvrhov a implementan kompromisy
21. Podpora zkladnch typ realizace DI
Constructorinjection
Bezpenj, Pehlednj
Nepovinn zvislosti, Cyklick zvislosti (proxy)
Setterinjection
Nepovinn i velk mnostv zvislost
Chybjc zvislosti (@Required)
Fieldinjection
Jednoduch zpis
Netransparentn
Pro
Pro rzn ppady se hod rzn pstupy
21
24 June 2009
22. Metadata pro popis komponent
Anotace
Jednoduch zpis
Zapeen na rovni kdu
XML
Ukecan
Lze mnt v deploymenttime
Konfigurovateln komponenty (vazba na infrastrukturu)
Pro
Obvykle oba typy komponent v aplikace
22
24 June 2009
23. Jak najt obrzky pro prezentaci
23
24 June 2009
24. 24
24 June 2009
25. Reference mezi komponentami
Typem
Bezpenj (Teoreticky)
Jedna instance komponenty
Sbr podle typu
Extenzibilita s volnou vazbou
Symbolickm jmnem
Vce instanc stejnho rozhran
Variabilnj skldn
XML
Pro
Testovn (mockobjecty se stejnm rozhranm)
25
24 June 2009
26. zen vzniku komponent
Uvnit kontextu
Delegace
Factory, Fctory metod
Mimo kontext
Deserializace komponenty
Web i ORM framework
Pro
Legacy kd, 3rd party knihovny
26
24 June 2009
27. zen poad vzniku
Pro
Nepm zvislosti
Zajitn explicitnho poad inicializace
27
24 June 2009
28. ivotn cyklus komponent
Jedna instance komponenty
Singleton
Nov instance komponenty
Prototyp
Konverzan instance komponenty
HTTP request, HTTP session atd.
Pro
Implementan detail komponenty
Web aplikace
28
24 June 2009
29. Dal
Programov pstup ke komponentm
Pro
Vstupn bod aplikace
Kd, kter si nen vdom obrcen kontroly
Legacy, Integrace s 3party knihovnami
Jednoduch testovatelnost
Pro
Efektivita vvoje
Facebook, Twitter, Freevideo
29
24 June 2009
30. Srovnn vybranch DI framework
31. Dependencyinjectionframeworky
Embeddedframeworky
PicoContainer 2.8
GoogleGuice 2.0
Aplikan frameworky
JBossMicrocontainer 2.0.6 GA
Springframework 2.5.x
Standard
ApacheOpenEJB 3.0
31
24 June 2009
32. 32
24 June 2009
33. Java Contexts and Dependency Injection (JSR-299)
WebBeans
Myths
JSR-299 is just for EJBs
JSR-299 is tied to JSF
JSR-299 is tied to heavyweight Java EE containers
JSR-299 uses a lot of annotations
33
24 June 2009
34. 34
24 June 2009
35. Questions?