// // 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 namespace di = boost::di; //<- struct interface1 { virtual ~interface1() noexcept = default; }; struct interface2 { virtual ~interface2() noexcept = default; }; struct implementation1 : interface1 {}; struct implementation2 : interface2 {}; //-> /**/ class example { public: example(std::unique_ptr up, std::shared_ptr sp, int i) { assert(dynamic_cast(up.get())); assert(dynamic_cast(sp.get())); assert(42 == i); } }; /**/ class example_with_different_parameters_order { public: example_with_different_parameters_order(std::shared_ptr sp, int i, std::unique_ptr up) { assert(dynamic_cast(up.get())); assert(dynamic_cast(sp.get())); assert(42 == i); } }; /**/ class example_with_different_parameters_order_and_types { public: example_with_different_parameters_order_and_types(std::unique_ptr sp, const int& i, interface1* up) : up_(up) { assert(dynamic_cast(up)); assert(dynamic_cast(sp.get())); assert(42 == i); } // in order to delete pointer - Boost.DI always transfer ownership to user in case of pointers std::shared_ptr up_; }; int main() { /*<>*/ // clang-format off auto injector = di::make_injector( di::bind().to() , di::bind().to() , di::bind().to(42) ); // clang-format on /**/ injector.create(); injector.create(); injector.create(); }