Boost logo

Boost :

Subject: Re: [boost] List of C++ 11 only Boost libraries and their status?
From: Kris (krzysztof_at_[hidden])
Date: 2014-11-24 17:11:03

> Remind me what it does again would you (a quick glance at the Readme
> did not help)?

Boost.DI it's a dependency injection
( library improving manual
dependency injection by simplifying object instantiation with automatic
dependencies injection.
It's a bit like Google Guice for Java ( or
Ninject for C# (

The simplest example di is good at:

struct iwriter { ~iwriter() = default; virtual void write() = 0; };
struct writer_impl : iwriter { void write() override {} };

class hello_world {
    hello_world(unique_ptr<iwriter> writer) : writer(writer) { } //
construct with iwriter dependency
    void run() { writer.write(); }

         unique_ptr<iwriter> writer;

int main() {
    // automatic dependency using boost.di
    auto injector = di::make_injector(
        di::bind<iwriter, writer_impl> // bind interface to implementation
    injector.create<hello_world>().run(); // construct hello world and run

    // manual dependency injection
    auto writer = make_unique<writer_impl>();
    hello_world{writer}.run(); // construct hello world and run it

Obliviously automatic di has a lot of pros which can't be seen in above
example, you can read a bit more in:

> Was it that new way of doing unit testing thing
> discussed here some time ago?
Well, not sure what was discussed, but automatic di let you implement
automatic mocks injection, which is really cool and basically let you get
rid of writing mocks and creating them for tests

Hope that helps a bit.

Cheers, Kris

View this message in context:
Sent from the Boost - Dev mailing list archive at

Boost list run by bdawes at, gregod at, cpdaniel at, john at