Proyectos
boost-ext/di has 1,278 GitHub stars and 149 forks. GitHot measured 0 stars in 24 hours, -1 in 7 days, and +1 in 15 days. Last checked 2026-11-23 20:07 UTC. Last push 2026-09-11.
Crecimiento de estrellas medido
- in 24h
- 0
- in 7 days
- -1
- in 15 days
- +1
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
Acerca de
Biblioteca de inyección de dependencias para C++14
Herramientas de desarrolloREADME.md
Originalboost-ext.di
Your C++14 one header only Dependency Injection library with no dependencies
Quick start
Download
boost-ext.di requires only one file. Get the latest header here!
Include
#include <boost/di.hpp>
namespace di = boost::di;
Compile
- GCC/Clang
$CXX -std=c++14 -O2 -fno-exceptions -fno-rtti -Wall -Werror -pedantic-errors file.cpp - MSVC
cl /std:c++14 /Ox /W3 file.cpp
Quick guide - Create object graph
class ctor {
public:
explicit ctor(int i) : i(i) {}
int i;
};
struct aggregate {
double d;
};
class example {
public:
example(aggregate a, const ctor& c) {
assert(87.0 == a.d);
assert(42 == c.i);
};
};
int main() {
const auto injector = di::make_injector(
di::bind<int>.to(42),
di::bind<double>.to(87.0)
);
injector.create<example>();
}
| 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 |
|
Quick guide - Bind interfaces
struct interface {
virtual ~interface() noexcept = default;
virtual int get() const = 0;
};
class implementation : public interface {
public:
int get() const override { return 42; }
};
struct example {
example(std::shared_ptr<interface> i) {
assert(42 == i->get());
}
};
int main() {
const auto injector = di::make_injector(
di::bind<interface>.to<implementation>()
);
injector.create<std::unique_ptr<example>>();
}
| 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 (same as `make_unique`) |
|
Quick guide - Bind templates
template<class ErrorPolicy = class TErrorPolicy>
class simple_updater {
public:
void update() const {
ErrorPolicy::on("update");
}
};
template<class Updater = class TUpdater>
class example {
public:
explicit example(const Updater& updater)
: updater(updater)
{ }
void update() {
updater.update();
}
private:
const Updater& updater;
};
int main() {
struct throw_policy {
static void on(const std::string& str) {
throw std::runtime_error(str);
}
};
const auto injector = di::make_injector(
di::bind<class TErrorPolicy>.to<throw_policy>(),
di::bind<class TUpdater>.to<simple_updater>()
);
injector.create<example>().update();
// Terminates with an uncaught exception because of our bound error policy
}
| 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 |
|
Quick guide - Bind concepts
struct Streamable {
template<class T>
auto requires(T&& t) -> decltype(
int( t.read() ),
t.write(int)
);
};
template<class Exchange = Streamable(class ExchangeStream)
class Engine = Streamable(class EngineStream)>
class example {
public:
example(Exchange exchange, Engine engine)
: exchange(std::move(exchange)), engine(std::move(engine))
{ }
private:
Exchange exchange;
Engine engine;
};
int main() {
const auto injector = di::make_injector(
di::bind<Streamable(class ExchangeStream)>.to<exchange>(),
di::bind<Streamable(class EngineStream)>.to<engine>()
);
injector.create<example>();
}
| 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
- Do I use a Dependency Injection already?
- Do I use Dependency Injection correctly?
- Do I need a Dependency Injection?
- STUPID vs SOLID - "Clean Code" Uncle Bob
- Do I need a DI Framework/Library?
- Manual DI - Wiring Mess (Avoid it by using [Boost].DI)
- Real Life examples?
- Why [Boost].DI?
- [Boost].DI design goals
- Articles
- Videos
- [Boost::ext].DI
- Dependency Injection In General
- Acknowledgements
- Overview
- Tutorial
- Try It Online!
- Benchmarks
- User Guide
- Examples
- Hello World
- Bindings
- Dynamic Bindings
- Forward Bindings
- Is Creatable
- Multiple Bindings
- Binding Non-owning Pointer
- Binding Templates
- Binding To Constructor
- 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
- Polymorphism
- Inheritance
- Type Erasure
- Function
- Variant
- Templates
- Concepts
- Extensions
- FAQ
- CHANGELOG
Disclaimer boost-ext.di is not an official Boost library.
Explorar proyectos relacionados
Cargando…
