SlideShare a Scribd company logo
1 of 54
Download to read offline
How to write custom IoC
created by Anuar Nurmakanov 1
About me
Kazakhstan, Karaganda
Lead Software
Engineer
XP/EngX Practices fan
Agile Believer
And I love Java!
2
JEEConf 2017 Program
It's me
Professional
Speakers
3
3 things should be
done by every
developer
4
Develop your custom framework
One of the many frameworks
5
What for????
to know implementation details
6
What we need
Bean registration
Auto search
Injection
Scopes
https://github.com/sshogunn/c
ustom-ioc-tdd
7
DI History
8
Manual Object Creation
JiaoziMachine
DoughMachine
VegetablesCutter
MeetGrinder
9
Dep 1 Dep 2
Dep 1
Dep 1 Dep 2
Dep 1 Dep 2
Dep 1
10
Factories
Abstract Factory Factory Method Static Factory Method
How much do we win if we use factories?
11
Service Locator
Factory Pattern
Service Locator
What is difference
between factories and
service locators?
12
13
Inversion of Control
14
IoC vs DI
15
Timer IoC example
Set Up timer
Do something
16
Unit Testing IoC example
@Test
public void shouldDoDomethingWhenSomethingElseHappened() {
//GIVEN
//WHEN
//THEN
}
def "#person.name is a #sex.toLowerCase() person"() {
expect:
person.getSex() == sex
where:
person || sex
new Person(name: "Fred") || "Male"
new Person(name: "Wilma") || "Female"
}
Is called by
Is called by
17
DI and IoC example
Who is this magic "injector"?
18
Spring and Guice
19
Guice High-Level View
20
Spring and Injector? WTF?
21
Let's do this
22
XML vs Annotations vs Java
Config
We will choose annotations 23
Ingredients
Annotations Test Cases
Basic Structure Idea!
24
Injector
25
Injector Idea
Injector
Tomato DependencySoup
Inject
26
Injector Lifecycle
Application Life
Injector 1
Injector 2 Injector 3
Injector 4
27
Beans
28
Register Beans
How we can register beans in
our framework?
29
What if
I want to register Objects as beans?
30
“ I have a POJO...
How can I make a bean ?
Searching for beans
31
Injection
32
One day you will have to
Inject dependencies
33
Injection Types
Injection Type
Constructor Property
Classic Types of
Injection only
34
No exotic
interface
injection
decorator
injection
35
What if
I want to inject more than one
dependency?
36
IdentifiersString key vs Type Key vs Composite key
37
A bean can be identified by type
Weapon.class identifies
Machete beans
Katana beans
Fighter.class identifies Fighter beans
WiiGame.class identifies HalfLife beans
Wii.class identifies Wii beans
38
What if
I have two beans of the same type?
39
String key identifier
TreeSet HashSet
How would you identify objects created from
this classes, if you asked to do so?
40
firstSet secondSet
treeSet hashSet
binaryTree
Set
hashTable
Set
set.Binary
Tree
set.Hashta
ble
41
How it could be with XML
<beans ...>
<bean id="weapons.Katana" class="Katana"/>
<bean id="weapons.Machete" class="Machete"/>
<bean id="fighters.Brazilian" class="Fighter">
<constructor-arg ref="weapons.Machete"/>
</bean>
<bean id="fighters.Ninja" class="Fighter">
<constructor-arg ref="weapons.Katana"/>
</bean>
</beans>
<beans ...>
<bean id="set.HashTable" class="java.util.HashSet"/>
<bean id="set.BinaryTree" class="java.util.TreeSet"/>
</beans>
42
Katana
Weapon
String key
Type key
Key 1: [Weapon.class, "katana"]
Key 2: [ Weapon.class, "machete"]
Key X: [Training.class, "Dependency Injection"]
Key Y: [ Training.class, "Bla-bla-bla Training"]
String Key + Type Key
43
Scope
44
Injector Lifecycle
45
Singleton Scope
A singleton’s context is the
injector
itself. The life of a singleton is
tied to the life of
the injector
Application
Injector 1
Injector 2 Injector ...
Injector N
46
Singleton Scope vs Singleton
For Singleton Pattern, it's
true, but per
For Singleton Scope, it's
true, but per
47
Prototype
Singleton life cycle is
bound to life cycle of
an injector
No scope is not
bound to life cycle of
injector
48
Any other features?
49
What if implement all of
them?
+ 1 IoC
Monstr
50
Recommendations
Picocontainer
51
I hope it was not boring =)
Questions and answers time!
52
I am happy to present
KZ in JEEConf 2017 53
@ssshogunnn
https://github.
com/sshogunn
54

More Related Content

Similar to How to write custom IoC framework

Similar to How to write custom IoC framework (20)

Core Java Certification
Core Java CertificationCore Java Certification
Core Java Certification
 
Certified Core Java Developer
Certified Core Java DeveloperCertified Core Java Developer
Certified Core Java Developer
 
Productive Debugging
Productive DebuggingProductive Debugging
Productive Debugging
 
What is Java? Presentation On Introduction To Core Java By PSK Technologies
What is Java? Presentation On Introduction To Core Java By PSK TechnologiesWhat is Java? Presentation On Introduction To Core Java By PSK Technologies
What is Java? Presentation On Introduction To Core Java By PSK Technologies
 
Java
Java Java
Java
 
Механизмы предотвращения атак в ASP.NET Core
Механизмы предотвращения атак в ASP.NET CoreМеханизмы предотвращения атак в ASP.NET Core
Механизмы предотвращения атак в ASP.NET Core
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
 
Developing an Ember Test Strategy - EmberConf 2019
Developing an Ember Test Strategy - EmberConf 2019Developing an Ember Test Strategy - EmberConf 2019
Developing an Ember Test Strategy - EmberConf 2019
 
Seeding a Tree in a Gherkin
Seeding a Tree in a GherkinSeeding a Tree in a Gherkin
Seeding a Tree in a Gherkin
 
How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your database
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSilicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your database
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
Clonedigger-Python
Clonedigger-PythonClonedigger-Python
Clonedigger-Python
 
Safety Bot Guaranteed -- Shmoocon 2017
Safety Bot Guaranteed -- Shmoocon 2017Safety Bot Guaranteed -- Shmoocon 2017
Safety Bot Guaranteed -- Shmoocon 2017
 
Mocking vtcc3 - en
Mocking   vtcc3 - enMocking   vtcc3 - en
Mocking vtcc3 - en
 
MongoDB Sharding
MongoDB ShardingMongoDB Sharding
MongoDB Sharding
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques
 
Anti Debugging
Anti DebuggingAnti Debugging
Anti Debugging
 

Recently uploaded

Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
drm1699
 

Recently uploaded (20)

Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...
Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...
Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaUNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmux
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Abortion Clinic In Pongola ](+27832195400*)[ 🏥 Safe Abortion Pills In Pongola...
Abortion Clinic In Pongola ](+27832195400*)[ 🏥 Safe Abortion Pills In Pongola...Abortion Clinic In Pongola ](+27832195400*)[ 🏥 Safe Abortion Pills In Pongola...
Abortion Clinic In Pongola ](+27832195400*)[ 🏥 Safe Abortion Pills In Pongola...
 

How to write custom IoC framework