// // 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; /**/ class custom_scope { public: /**/ class entry {}; class exit {}; template class scope { /**/ class custom_wrapper { public: custom_wrapper(const std::shared_ptr& object) // non explicit : object_(object) {} /*<>*/ inline operator std::shared_ptr() const noexcept { return object_; } std::shared_ptr object_; }; public: template using is_referable = std::false_type; template static custom_wrapper try_create(const TProvider&); /*<>*/ template custom_wrapper create(const TProvider& provider) const noexcept { return std::shared_ptr{provider.get()}; } }; }; struct example { explicit example(const std::shared_ptr& sp) : sp_(sp) {} std::shared_ptr sp_; }; int main() { /*<>*/ // clang-format off auto injector = di::make_injector( di::bind().in(custom_scope{}) ); // clang-format on assert(injector.create().sp_); }