#[Boost].DI
Your C++14 header only Dependency Injection library with no dependencies (Try it online!)
// $CXX -std=c++14 -O2 -fno-exceptions -fno-rtti -Wall -Werror -pedantic-errors hello_world.cpp
// cl /std:c++14 /Ox /W3 hello_world.cpp (***)
#include <boost/di.hpp>
#include <cassert>
#include <iostream>
namespace di = boost::di;
struct iworld {
virtual ~iworld() noexcept = default;
};
struct world : iworld {
world() { std::cout << " world!" << std::endl; }
};
struct hello {
explicit hello(int i) {
assert(42 == i);
std::cout << "hello";
}
};
// aggregate initialization `example{hello, world}`
struct example {
hello h;
iworld& w;
};
int main() {
const auto injector = di::make_injector(
di::bind<iworld>().to<world>()
, di::bind<>().to(42)
);
injector.create<example>();
}
###Benchmark
<td rowspan="4">
<a href="http://boost-experimental.github.io/di/benchmarks/index.html#benchmarks">More Benchmarks</a>
</td>
Clang-3.8 | GCC-6 | MSVC-2015 | |
---|---|---|---|
Compilation Time | 0.102s | 0.118s | 0.296s |
Binary size (stripped) | 6.2kb | 6.2kb | 105kb |
ASM x86-64 |
|
###Documentation
- Introduction
- Overview
- Tutorial
- Try It Online!
- Benchmarks
- User Guide
- Examples
- Hello World
- Bindings
- Dynamic Bindings
- Forward Bindings
- Multiple Bindings
- Binding Non-owning Pointer
- Automatic Injection
- Constructor Signature
- Constructor Injection
- Multiple Interface
- Annotations
- Deduce Scope
- Custom Scope
- Eager Singletons
- Modules
- Modules (hpp/cpp)
- Custom Policy
- Custom Provider
- Pool Provider
- Configuration
- Extensions
- FAQ
- CHANGELOG