// // 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 "boost/di/extension/injections/xml_injection.hpp" #include #include namespace di = boost::di; //<- struct interface { virtual ~interface() noexcept = default; }; struct implementation1 : interface {}; struct implementation2 : interface {}; struct xml_parser_stub : di::extension::ixml_parser { std::string parse(const std::string&) override { static auto i = 0; switch (i++) { default: return {}; case 0: return typeid(implementation1).name(); case 1: return typeid(implementation2).name(); }; return {}; } }; //-> auto module = [] { // clang-format off return di::make_injector( di::bind().to() ); // clang-format on }; auto xml_module = [] { // clang-format off return di::make_injector( di::bind().to(di::extension::xml()) ); // clang-format on }; int main() { /*<>*/ auto injector = di::make_injector(module(), xml_module()); /*<>*/ { auto object = injector.create>(); assert(object.get()); assert(dynamic_cast(object.get())); } /*<>*/ { auto object = injector.create>(); assert(object.get()); assert(dynamic_cast(object.get())); } /*<>*/ { auto object = injector.create>(); assert(!object.get()); } }