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
(http://en.wikipedia.org/wiki/Dependency_injection) library improving manual
dependency injection by simplifying object instantiation with automatic
dependencies injection.
It's a bit like Google Guice for Java (https://github.com/google/guice) or
Ninject for C# (http://www.ninject.org).

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 {
public:
    hello_world(unique_ptr<iwriter> writer) : writer(writer) { } //
construct with iwriter dependency
    void run() { writer.write(); }

    private:
         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
it

    // 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:
http://krzysztof-jusiak.github.io/di/boost/libs/di/doc/html/di/introduction.html

> 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
(https://github.com/krzysztof-jusiak/mocks_injector)

Hope that helps a bit.

Cheers, Kris

--
View this message in context: http://boost.2283326.n4.nabble.com/List-of-C-11-only-Boost-libraries-and-their-status-tp4669425p4669466.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk