Without dependency injection | With the introduction of addiction |
---|---|
| |
Manual dependency injection | Boost.DI |
---|---|
| |
// main.cpp #include "di.hpp" int main() { }
$CXX -std=c++1y -I. main.cpp
#include <boost/di.hpp> namespace di = boost::di; // struct i1 { virtual ~i1() = default; virtual void dummy1() = 0; }; struct i2 { virtual ~i2() = default; virtual void dummy2() = 0; }; struct impl1 : i1 { void dummy1() override { } }; struct impl2 : i2 { void dummy2() override { } }; struct impl : i1, i2 { void dummy1() override { } void dummy2() override { } };
Creating an empty injector | Test |
---|---|
| |
Interface binding to implementation | Test |
---|---|
| |
Binding multiple interfaces to one implementation | Test |
---|---|
| |
Type binding to the value calculated at compile time | Test |
---|---|
| |
Type binding to value | Test |
---|---|
| |
Implementation through the usual constructor | Test |
---|---|
| |
Implementing through aggregation | Test |
---|---|
| |
Implementation through the designer if available several constructors (the one with the largest number of parameters) | Test |
---|---|
| |
Implementation through the designer in the presence of options selection (using BOOST_DI_INJECT) | Test |
---|---|
| |
Implementation through the designer in the presence of options selection (using BOOST_DI_INJECT_TRAITS) | Test |
---|---|
| |
Implementation through the designer in the presence of options choice (using di :: ctor_traits) | Test |
---|---|
| |
Implementation through annotated constructors | Test |
---|---|
| |
Implementation through annotated constructors with using named parameters | Test |
---|---|
| |
Implementation through annotated constructors with making implementation of the constructor | Test |
---|---|
| |
Implementation through annotated constructors with using di :: ctor_traits | Test |
---|---|
| |
Display scope (default) | Test |
---|---|
| |
Type of | Derived scope |
---|---|
T | unique |
T & | error - must be linked as external |
const T & | unique (temporary) |
T * | unique (transfer of ownership) |
const T * | unique (transfer of ownership) |
T && | unique |
unique_ptr | unique |
shared_ptr | singleton |
weak_ptr | singleton |
Unique scope | Test |
---|---|
| |
Shared visibility (within the stream) | Test |
---|---|
| |
Singleton (shared between streams) | Test |
---|---|
| |
Scope of session | Test |
---|---|
| |
Outer scope | Test |
---|---|
| |
Special scope | Test |
---|---|
| |
Module | Test |
---|---|
| |
Module opening type | Test |
---|---|
| |
The module that opens several types | Test |
---|---|
| |
Open type module with annotation | Test |
---|---|
| |
"No throw" provider | Test |
---|---|
| |
Defining configuration policies (dump types) | Test |
---|---|
| |
Defining configuration policies (detailed type dump) | Test |
---|---|
| |
"Can be constructed" policy | Test |
---|---|
| |
Creating a type without bindings | Asm x86-64 (same as "return 0") |
---|---|
| |
Creating a type with object binding | Asm x86-64 (same as "return 42") |
---|---|
| |
Create Named Type | Asm x86-64 (same as "return 42") |
---|---|
| |
Creating an interface binding to the implementation | Asm x86-64 (same as make_unique) |
---|---|
| |
Creating an interface binding through a module | Asm x86-64 (same as make_unique) |
---|---|
| |
Creating an interface binding through an open module | Asm x86-64 price = virtual method call |
---|---|
| |
Header file Boost.DI | Time [sec] |
---|---|
| 0.165 |
Creating an interface without reference to the implementation | Error message |
---|---|
| |
Binding ambiguity | Error message |
---|---|
| |
Creating an object without bindings with policies requiring them | Error message |
---|---|
| |
Invalid annotation syntax (NAMED instead of named) | Error message |
---|---|
| |
Macro | Description |
---|---|
| |
Source: https://habr.com/ru/post/248879/
All Articles