// // This file is part of dingo project // // See LICENSE for license and copyright information // SPDX-License-Identifier: MIT // // Include required dingo headers #include #include #include int main() { using namespace dingo; //// // User types do not need Dingo-specific base classes or macros. struct A { A() = default; }; struct B { B(A &, std::shared_ptr) {} }; struct C { C(B *, std::unique_ptr &, A &) {} }; container<> container; // A and B are shared, so every resolution reuses the same instances. container.register_type, storage>>(); container.register_type, storage>>(); // C is unique, so every resolve() creates a fresh C. container.register_type, storage>(); // Constructor arguments are resolved recursively, including ownership // conversions from the registered storage forms. C c = container.resolve(); struct D { A &a; B *b; }; // Construct an unmanaged object using dependencies from the container. D d = container.construct(); // Or invoke a callable with resolved arguments. D e = container.invoke([&](A &a, B *b) { return D{a, b}; }); //// (void)c; (void)d; (void)e; }