Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1) Statically defined collection? Dependencies are available at runtime. 2) That matching criteria is vtable logic, as C does not support polymorphism, as a language feature. Commented Jul 27, 2017 at 23:05
  • By statically defined I mean the same instance is shared between all invocations. You can't have one set of objects in one part of your program and a different set in another part, because there's only a single pointer to the dependencies shared by all clients. In a dependency injection system, each client gets their own copy of the pointer so that they can have a different dependency if necessary. Commented Jul 28, 2017 at 8:20
  • For every vdrawImage(filename) we get corresponding dependency(handleno = find_handler(filename);), based on the filename passed to vdrawImage(). Isn't it? Commented Jul 28, 2017 at 8:26
  • What if you want two different calls to vdrawImage("test.png") to use a different implementation of your handler object? They both call the same file_handler function that pulls the same object out of global data. This is the main distinction between dependency injection and the service locator pattern. Service locators are great for many things, but they're hard to write unit tests against, because very often different tests want to use different mock implementations in otherwise indistinguishable calls to the locator. Commented Jul 28, 2017 at 16:37
  • Can this dependency container be called as IOC container? Commented Dec 14, 2017 at 16:59