As mentioned in this article,
Inversion of Control can be achieved through various mechanisms such as: Strategy design pattern, Service Locator pattern, Factory pattern, and Dependency Injection (DI).
Am missing clarity in above statement,
because my understanding is, 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()
perform the job of creating a container of implementations configured in config.txt
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, based on given input(scanf("%s",filename);
)
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
, and
MessageBean mBean = (MessageBean)appContext.getBean("messagebean");
locates the messageBean
service using service locator pattern from that container.
Is it the right understanding?