Sorin Damian - Using and Abusing Dependency Injection Containers
-
Upload
codecampiasi -
Category
Documents
-
view
284 -
download
4
Transcript of Sorin Damian - Using and Abusing Dependency Injection Containers
![Page 1: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/1.jpg)
Using and Abusing
Dependency Injection
ContainersSorin Damian
SC RomSoft SRL (rms.ro)
[10th of November 2012]
![Page 2: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/2.jpg)
Why do YOU use it?
![Page 3: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/3.jpg)
UGLY DEMO
![Page 4: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/4.jpg)
The Inversion of Control Principle
Don’t ask for information
Ask for help
![Page 5: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/5.jpg)
IoC – Don’t call us, we’ll call you
![Page 6: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/6.jpg)
IoC for 5 year olds
When you go and get things out of the
refrigerator for yourself, you can cause problems.
You might leave the door open, you might get
something Mommy or Daddy doesn't want you to
have. You might even be looking for something
we don't even have or which has expired.
What you should be doing is stating a need, "I
need something to drink with lunch," and then we
will make sure you have something when you sit
down to eat. http://stackoverflow.com/questions/1638919/how-to-explain-dependency-injection-to-a-5-year-old
![Page 7: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/7.jpg)
NICER BUT STILL
UGLY DEMO
![Page 8: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/8.jpg)
Dependency Injection
Design pattern
The Inversion of Control principle
applied to dependency management
Ask for dependencies
Instantiating them is a separate concern
![Page 9: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/9.jpg)
What you get
+ decupling
+ reusability
+ testability
- more code
- more ceremony
- composition hell
![Page 10: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/10.jpg)
![Page 11: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/11.jpg)
DEMO (15 lines container)
![Page 12: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/12.jpg)
DEMO (using the container)
![Page 13: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/13.jpg)
If it looks like a factory..
And it works like a factory..
![Page 14: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/14.jpg)
![Page 15: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/15.jpg)
Call the container only at
the composition root!
![Page 16: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/16.jpg)
Every time you call the container to
get your dependencies a kitten dies..
![Page 17: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/17.jpg)
Any questions?
![Page 18: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/18.jpg)
Thank you!
![Page 19: Sorin Damian - Using and Abusing Dependency Injection Containers](https://reader034.fdocuments.net/reader034/viewer/2022052601/559532591a28aba15f8b4603/html5/thumbnails/19.jpg)
Diamond Sponsors
Platinum Sponsors Gold Sponsors
Training Partners Media Partners Other Partners