Background
As mentioned in this article,
Inversion of Control can be achieved through various mechanisms such as: Strategy design pattern, Service Locator pattern(SLP), Factory pattern, and Dependency Injection (DI).
Am missing clarity in above statement, because below is my understading.
1) Creation of container
Creating a dependency container or IOC container does not require any of these design patterns(mentioned above). We need these design patterns to get access to an implementation from that container(which is already created). Here is the C code where init_handlers()
create a container(imagehandlers
in config.c) of implementations that are configured in config.txt
2) Access impl from the container
To get access to an implementation from the container, for example,
One can rely on injection mechanism that is implementated using DI pattern.
or
Rely on service location mechanism that is implemented using Service locator pattern. Here is the C code where displayMenu()
locates the service from imagehandlers
container, based on given input(scanf("%s",filename);
)
So, Dependency Injection or Service locator pattern has nothing to do with creation of IOC container but to get access to an implementation from that container.
For example, In Spring,
ApplicationContext appContext = new ClassPathXmlApplicationContext("Springbeans.xml")
create the IOC container with singleton instances of all beans configured in Springbeans.xml
assuming the beans are not prototype-scoped and
MessageBean mBean = (MessageBean)appContext.getBean("messagebean");
locates the messageBean
service using service locator pattern from appContext
container.
1) For this line of code ApplicationContext appContext = new ClassPathXmlApplicationContext("Springbeans.xml")
that creates a dependency container, Is it right to say that, creation of container has nothing to do with design pattern(like DI or SLP)?
2) Why appContext
is not called a dependency container? Instead, why appContext
is called IOC container?