IOC CONTAINER
FROM SCRACH
ŁUKASZ DZIEDZIUL
1
2002
2
2002
3
2004
4
2004
5
2005
6
2005
7
2019
8
9
Co by się stało gdyby Spring zniknął na tydzień…?
10
11
2020?
12
2020?
13
WITHOUT
https://www.jetbrains.com/lp/devecosystem-2019/java/
14
SPRING FRAMEWORK
▸ IoC Container
▸ Aspects
▸ Transactions
▸ MVC
▸ JDBC/ORM
▸ …
15
IOC CONTAINER
16
IOC CONTAINER
▸ Objects define their dependencies but don’t control instantiation
▸ Instead of a client specifying which service it will use, something tells the client
what service to use.
17
SHOW ME THE CODE
18
CONTEXT
19
CONTEXT
▸ Surrounding of bean creation and code execution
▸ Context creation phases:
▸ Gathering info about the beans
▸ Actual bean creation
▸ Populating the context
20
CONTEXT
21
CONTEXT
22
CONTEXT
23
CONTEXT
24
CONFIGURATION
25
CONFIGURATION
▸ List of bean definition along with dependencies
26
CONFIGURATION
27
▸ List of bean definition along with dependencies
▸ Types
▸ Xml
▸ Annotations
▸ Java Config
CONFIGURATION
▸ List of bean definition along with dependencies
▸ Types
▸ Xml
▸ Annotations
▸ Java Config
▸ Non-invasive
▸ Testable
▸ Ready-to-use state of beans
28
CONFIGURATION
29
CONFIGURATION
30
CONFIGURATION
31
▸ How to use it?
CONFIGURATION
32
▸ Plan: simply run all bean methods from configuration objects
▸ How:
▸ Find configurations
▸ Create configurations
▸ Call bean methods
CONFIGURATION - FIND
33
CONFIGURATION - CREATE
34
BEAN DEFINITION
35
CONFIGURATION
36
BEAN DEFINITION
▸ Metadata about the bean:
37
BEAN DEFINITION
▸ Metadata about the bean:
▸ Bean type
38
BEAN DEFINITION
▸ Metadata about the bean:
▸ Bean type
▸ Dependencies
39
BEAN DEFINITION
40
BEAN DEFINITION
▸ Metadata about the bean:
▸ Bean type
▸ Dependencies
▸ Instantiation method
41
BEAN DEFINITION
42
BEAN DEFINITION
43
BEAN DEFINITION
44
BEAN FACTORY
45
BEAN FACTORY
▸ Creates actual bean from BeanDefinition
▸ Initialises context with beans
46
BEAN FACTORY
47
BEAN FACTORY
48
BEAN FACTORY
49
BEAN FACTORY
50
BEAN FACTORY
51
BEAN FACTORY
52
MVP?
53
MVP?
54
MVP?
55
CYCLIC DEPENDENCY
56
CYCLIC DEPENDENCY
57
CYCLIC DEPENDENCY
58
SUMMARY
59
SUMMARY
60
SPRING FRAMEWORK IMPLEMENTATION
▸ org.springframework.beans.factory.BeanFactory
▸ org.springframework.beans.factory.BeanCurrentlyInCreationException
▸ org.springframework.beans.factory.config.BeanPostProcessor
▸ org.springframework.beans.factory.config.BeanDefinition
▸ org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
▸ org.springframework.context.ApplicationContext
61
TAKEAWAYS
▸ You know dependency injection - constructors
▸ Spring is simple, additions are hard to understand
▸ Do you need full blown spring boot? Especially for serverless
▸ Make your domain framework agnostic.
62
HOMEWORK
▸ https://github.com/ldziedziul/diy-ioc-container
63
HOMEWORK
▸ https://github.com/ldziedziul/diy-ioc-container
▸ Add
▸ Transactions
▸ List of beans
▸ Injection by super types
▸ Circuit breaker
▸ Metrics
64
LINKS
▸ https://github.com/cbeams/spring-framework-i21
▸ https://www.jetbrains.com/lp/devecosystem-2019/java/
▸ https://martinfowler.com/articles/injection.html
▸ https://github.com/ronmamo/reflections
65
ABOUT ME
▸ @ldziedziul
▸ @jSessionPL
▸ @Programistok
▸ @CasumoTech
66
QUESTIONS?
67

IoC container from scratch