Reputation: 8943
I am trying to understand Spring Framework more what I know currently, and I am referring to "Pro Spring 3" book.
It says that in general IoC
can be decomposed into two components viz:
Dependency Injection
and Dependency Lookup
.
With respect to this, I have following questions:
1) Do Spring provide both Dependency Injection
,Dependency Lookup
?
2) Do all Ioc
container have both these systems viz: Dependency Injection
,Dependency Lookup
?
3) If Spring provides both Dependency Injection
,Dependency Lookup
, then isn't it wrong to say that Spring is DI framework, when it has both these capabilities?
Upvotes: 1
Views: 843
Reputation: 206996
1: Yes, Spring provides both dependency injection and dependency lookup. You can let Spring inject dependencies using for example the @Autowired
annotation, and you can also manually lookup components from Spring's ApplicationContext
by calling one of the getBean
methods.
The main thing to understand about the concept "inversion of control" (IoC) is that Spring does the work for you, instead of the other way around: you let Spring create instances of your components, and you let Spring inject the dependencies, instead of the other way around, where you write code yourself to create instances and lookup dependencies.
2: No, not necessarily.
3: Spring can do dependency injection (DI), so it is a DI framework. Just because it also does other things (such allow you to lookup components explicitly) doesn't suddenly not make it a DI framework anymore.
Upvotes: 2