Dependency Injection in C++

Dependency Injection is a powerful software design technique promoting component-based design and enabling complete component logic isolation from initialization time boilerplate. As a useful consequence, components written for dependency injection have well defined interfaces, can be exhaustively tested with unit tests and can thus be used as generic architectural building block without the fear of exciting a new execution path (opposed to typically solid design of software systems written in a chaotic, "Jira-by-Jira" way). Java community can use dependency injection with minimum effort when using Spring Framework, whereas C++ community is traditionally ignorant to the maintenance and code reuse benefits so there is no single leader around. The article is a step-by-step how-to instruction on enabling dependency injection in C++ code on Linux.
Separate Bootstrapping and Business Logic
Separate Interface and Implementation
Use Dynamic Linking
Enforce Build Time Unresolved Symbols Check
The last, but not the least — build time hygiene. The Makefile used in the project is below. It demonstrates how to correctly build dynamic libraries on GNU Linux to make sure no runtime surprises with unresolved symbols ever occur.
CPPFLAGS:=-MMD -I/home/bobah/work/cpplibs/boost_1_47_0
LDFLAGS:=-m64 -fPIC -Wl,-zdefs -Wl,-znow

.PHONY: all
all: app

.PHONY: clean
	/bin/rm -f app
	$(CXX) -shared -Wl,-soname,$@.1 -o $@ $^ -m64 -fPIC -Wl,-zdefs -Wl,-znow
	$(CXX) -shared -Wl,-soname,$@.1 -o $@ $^ -m64 -fPIC -Wl,-zdefs -Wl,-znow 

	$(CXX) -o $@ $(LDFLAGS) $^ -m64 -fPIC -Wl,-zdefs -Wl,-znow -ldl

-include $(patsubst,%.d,$(wildcard *.cc))

plugin.tgz1.94 KB