DEPENDENCY OF BEANS
If a bean need other bean or beans for its working ten other beans are called dependencies of the
bean. Dependency of the bean can be of following type:
1. Dependency on primitive values (String are considered as primitive).
2. Dependency on other beans.
3. Dependency on collections.
Dependencies of beans can be satisfied using either of the following approach.
A. Dependency Injection
B. Dependency Lookup
In case of Dependency Injection, dependencies of the bean are satisfied by the container on its own
i.e. a bean user simply ask the container to provide the bean if the bean has some dependencies.
Container is not asked explicitly to satisfy them rather they are satisfied by container by its own.
In case of Dependency Lookup, dependencies are satisfied by the container only when its explicitly
asked to do so.
Spring IOC Container supports dependency Injection because it reduces the steps for the bean user.
Two strategies are supported by the container for injecting the dependencies
1. Constructor Injection 2. Setter Injection
In Constructor Injection, dependencies are satisfied by the container as constructor parameters. This
approach is used in case of mandatory dependencies.
In case of Setter Injection, dependencies are satisfied are parameter of setter methods, setter
Injection is used when dependencies are optional.
Following Example demonstrate the difference between these two approaches.
Let there be a bean named A which has a dependency on bean named B, if this dependency
injection following operations will be performed when the bean is requested.
UNDER PROCESSING
If a bean need other bean or beans for its working ten other beans are called dependencies of the
bean. Dependency of the bean can be of following type:
1. Dependency on primitive values (String are considered as primitive).
2. Dependency on other beans.
3. Dependency on collections.
Dependencies of beans can be satisfied using either of the following approach.
A. Dependency Injection
B. Dependency Lookup
In case of Dependency Injection, dependencies of the bean are satisfied by the container on its own
i.e. a bean user simply ask the container to provide the bean if the bean has some dependencies.
Container is not asked explicitly to satisfy them rather they are satisfied by container by its own.
In case of Dependency Lookup, dependencies are satisfied by the container only when its explicitly
asked to do so.
Spring IOC Container supports dependency Injection because it reduces the steps for the bean user.
Two strategies are supported by the container for injecting the dependencies
1. Constructor Injection 2. Setter Injection
In Constructor Injection, dependencies are satisfied by the container as constructor parameters. This
approach is used in case of mandatory dependencies.
In case of Setter Injection, dependencies are satisfied are parameter of setter methods, setter
Injection is used when dependencies are optional.
Following Example demonstrate the difference between these two approaches.
Let there be a bean named A which has a dependency on bean named B, if this dependency
injection following operations will be performed when the bean is requested.
UNDER PROCESSING
Comments
Post a Comment