A stupid-simple, zero-dependency, header-only DI framework for C++17
Switch branches/tags
Nothing to show
Clone or download
Failed to load latest commit information.
example Initial commit of rewrite Jun 3, 2018
include Fix gcc build: Don't use make_unique Jun 17, 2018
tests Test manual Get Jun 17, 2018
.travis.yml Travis for tests Jun 3, 2018
README.md Fix syntax highlighting on example Jun 3, 2018



Build Status

A stupid-simple, header-only, zero-dependency DI framework for C++17. What you see is what you get, nothing fancy, nothing crazy robust.


#include <iostream>
#include "BabyDI.hpp"

// Define a simple interface..
struct IAnimal {
  virtual void Speak() const = 0;

// Define a simple implementation of the interface..
struct Dog : public IAnimal {
  void Speak() const override {
    std::cout << "Woof!" << std::endl;

// Define a basic class which depends on IAnimal
struct BasicDependent {
  // Inject with alias, or alternatively use INJECT(IAnimal) for no alias
  // (Expands to a static inline variable..)
  INJECT(IAnimal, Animal);

  void CallImplementation() {
    Animal->Speak(); // Call the implementation

int main(int argc, char* argv[]) {
  // Provide IAnimal
  PROVIDE(IAnimal, new Dog())

  // Will fire the callback if not everything has been provided
  // Alternatively, calling this with no argument will use this same default callback
  BabyDI::AssertAllProvided([](auto& interfaceNames) {
    std::cerr << "BabyDI: Injections not provided:" << std::endl;

    for (const auto& interfaceName : interfaceNames) {
      std::cerr << "  " << interfaceName << std::endl;


  BasicDependent dependent;

  return 0;

Building Example

Running Tests