Skip to content
/ di Public
forked from boost-ext/di

[Boost].DI: C++14 Dependency Injection Library

Notifications You must be signed in to change notification settings

jhruby/di

 
 

Repository files navigation

Boost Licence Version Build Status Build Status Coveralls Github Issues


#[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

About

[Boost].DI: C++14 Dependency Injection Library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 83.1%
  • Java 9.8%
  • C# 4.4%
  • Python 0.8%
  • CMake 0.8%
  • Makefile 0.7%
  • Shell 0.4%