// // Copyright (c) 2012-2020 Kris Jusiak (kris at jusiak dot net) // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // //<- #include #include #include //-> #include namespace di = boost::di; //<- struct interface { virtual ~interface() noexcept = default; virtual void dummy() = 0; }; struct implementation1 : interface { void dummy() override {} }; struct implementation2 : interface { void dummy() override {} }; //-> struct data { std::shared_ptr sp; }; struct app { app(std::unique_ptr up, int i, double d, const data& data) { assert(dynamic_cast(up.get())); assert(i == 42); assert(d == 87.0); assert(dynamic_cast(data.sp.get())); } }; /*<<`module1` configuration>>*/ auto module1 = [] { // clang-format off return di::make_injector( di::bind().to() ); // clang-format on }; /*<<`module2` configuration>>*/ auto module2(const int& i) { // clang-format off return di::make_injector( di::bind().to(i) ); } // clang-format on /*<>*/ auto exposed_module = []() -> di::injector { // clang-format off return di::make_injector( di::bind().to() ); // clang-format on }; int main() { constexpr auto i = 42; constexpr auto d = 87.0; /*<>*/ // clang-format off auto movable_injector = di::make_injector( di::bind().to(d) ); // clang-format on /*<>*/ // clang-format off auto injector = di::make_injector( module1() , module2(i) , exposed_module() , std::move(movable_injector) ); // clang-format on /*<>*/ injector.create(); }