"Don't call us, we'll call you", Hollywood principle
This is not an official Boost library yet and there is no guarantee it will ever be!
Boost.DI is C++03/C++11/C++14 header only library providing type safe, compile time, macro free constructor dependency injection.
#include <boost/di.hpp>
namespace di = boost::di;
struct hello {
hello(const std::shared_ptr<i>& sp
, std::unique_ptr<int> up
, boost::function<int()> f)
: sp(sp)
{
assert(dynamic_cast<impl*>(sp.get()));
assert(*up == 0);
assert(f.empty());
}
std::shared_ptr<int> sp;
};
struct world {
world(hello copy
, boost::shared_ptr<i> sp
, const std::string& str
, int i)
{
assert(dynamic_cast<impl*>(sp.get()));
assert(copy.sp.get() == sp.get());
assert(str == "");
assert(i == 0);
}
};
struct app {
app(hello, world);
int run();
};
int main() {
auto injector = di::make_injector(
di::bind<i, impl>() // scope deduction -> di::shared<di::bind<i, impl>>
);
return injector.create<app>().run();
}
- Type safe
- Compile time approach - no exceptions - if application compiles all dependencies will be be created accurately
- Macro free - by default no need to specify constructor traits or register anything (less intrusive)
- Scopes deduction - scopes are deduced based on type semantic
- Automatic conversion between std/boost smart pointers
- Compile time policies - ex. to detect circular dependencies or limit supported types only to specified
- Supports C++03/C++11/C++14 standards
- Header only library
- Architecture independent (tested on x86/x86-64)
- Supports all POSIX and Windows operating systems (tested on Linux 3.8/Windows 7/8)
- Exception safe guaranty
- Thread safe guaranty
- Constructor injection (macro free)
- Compile time creation guaranty
- Dependencies life time management (scopes: deduce, external, unique, shared, session + custom scopes)
- Scope deduction (shared_ptr -> shared, unique_ptr, lvalue -> unique, ...)
- Supports copies, references, pointers, boost and std smart pointers / rvalue references(C++11)
- Named parameters (named<int, my_int>)
- Runtime visitor throughout created objects (useful for generation dependency diagrams)
- Documentation
- [Todo/Issues] (https://github.com/krzysztof-jusiak/di/issues?state=open)
- Boost Library Incubator - DI
-
Linux (x86/x86-64)
- Clang 3.2/3.3/3.4.2+ (clean with Clang Static Analyzer and Valgrind)
- GCC 4.7.3/4.8.2/4.9.0+ (clean with Valgrind)
- Intel C++ 14.0.3+ (clean with Valgrind)
-
Windows (x86/x86-64)
- MinGW 4.7.3/4.8.2+
- Visual Studio 2013+ (clean with DrMemory)
-
Darwin/Mac OS (x86-64)
- Clang 503.0.40+ (Apple LLVM version 5.1)
- https://bitbucket.org/cheez/dicpp
- https://code.google.com/p/infectorpp
- https://github.com/phs/sauce
- https://code.google.com/p/wallaroo
- https://code.google.com/p/hypodermic
- https://github.com/admiyo/CppInject
- http://qtioccontainer.sourceforge.net
- https://code.google.com/p/autumnframework
- http://sourceforge.net/projects/cpp-resolver
- https://code.google.com/p/pococapsule
- https://code.google.com/p/spring-cpp
- http://www.cs.utah.edu/~arichard/inject.html
- http://bobah.net/d4d/source-code/misc/cpp-dependency-injection
- https://code.google.com/p/ffead-cpp
- http://codebros.github.io/DiLite
- https://code.google.com/p/kindi
Distributed under the Boost Software License, Version 1.0.