Inversion of Control And Dependency injection
Here we are going to learn about basics and concepts of DI and IOC. Essentially, dependency injection is a form of IoC, but these two terms are often used interchangeably. IoC and DI, aims to provide a much simpler mechanism to achieve component dependenciesSpring container
Spring offers a container, known as spring application context, that creates and manages application components(Objects). These objects or beans bundled together inside the spring application context to make a complete application like our body bounded by all parts and individually they are doing their specific jobs. A spring container manages full life cycle of objects from its creation to destruction.
( Note : There are two types of IoC container implementations in spring. The basic one is called a bean factory. The more advanced one is called an application context, which is compatible with the bean factory )
Dependency injection Binding beans together is based on a pattern called as dependency injection (DI). A container is used to create and maintain all objects and inject these objects into beans that need them. For example, One class (Class A) may use other classes (Class B and C). So, Class B and C are dependencies of class A. Rather than Class A creates components(objects) for B,C and maintain the lifecycle of those beans , dependency-injected application (the container) creates and maintain all components and inject those into the beans that need them. Types of dependency injection : ➔ Constructor dependency injection ➔ Setter dependency injection Constructor dependency injection
No comments:
Post a Comment