As per wiki,
A dependency is an object that can be used (as a service).
here is the OOP paradigm using C syntax that address 4 roles, shown below.
1) interface (handlers.h)
typedef struct {
int (*canHandle) (char *);
int (*drawImage)(char *);
int (*savefile)(char *);
}imageHandler;
2) Take one Dependency (gifhandler.c)
imageHandler gifhandler = {
gif_canHandle,
gif_drawImage,
gif_savefile
};
3) Dependency container (dealt by config.c)
//gifhandler.c - dependency
int _init(){
printf(" registering gifhandler \n");
reg_handler(&gifhandler);
return 0;
}
//config.c
imageHandler *imagehandlers[10];
int reg_handler(imageHandler *ih){
// we need to perform checks here.
imagehandlers[libs] = ih;
libs++;
return TRUE;
}
// config.c
int init_handlers(){
.....
soptr = dlopen(so_name,RTLD_NOW);
....
}
4) Client - Service locator (UI.C)
// UI.C
switch(choice){
case 1:
vdrawImage(filename);
break;
case 2:
vsavefile(filename);
break;
}
// viml.c
int vdrawImage(char *filename){
...
handleno = find_handler(filename);
...
ih=imagehandlers[handleno];
ih->drawImage(filename);
return FALSE;
}
// viml.c
int vsavefile(char *newfilename ){
...
handleno = find_handler(newfilename);
...
ih=imagehandlers[handleno];
ih->savefile(newfilename);
}
1) To add new dependency(libxyzhandl.so.1) in Dependency container, it just requires adding a new entry in config.txt configurable, as shown below,
config.txt
./libgifhandl.so.1
./libtiffhandl.so.1
2) New service provided by ./libxyzhandl.so.1, will be contained by Dependency container without re-compilation of application.
3) Testing of complete application is not required, except source code of libxyzhandl.so.
So, if config.txt goes empty, then, application does nothing, except saying, We cannot handle this kind of files, shown here, for any input(image file).
Below is the visualisation of call flow,
Question:
Can this dependency container be called an IOC container?

imageHandleris constructed. Can you show me the line of code where it's happening?imagehandlers[10]is your construction code I need to know where that is and what else is going on there. I need context.extern imageHandler *imagehandlers[];inhandlers.h,imagehandlersis array of structure of pointers(vtable). Each element of array, houses behavior code