From 5864e5abc43b201c3801fa39a2fcaf9e3a9e8914 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 27 Feb 2022 12:54:10 +0100 Subject: refactor: use dependency injection --- src/DI/container.hpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/DI/container.hpp (limited to 'src/DI/container.hpp') diff --git a/src/DI/container.hpp b/src/DI/container.hpp new file mode 100644 index 0000000..2402894 --- /dev/null +++ b/src/DI/container.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include "DI/object_type.hpp" +#include "interfaces/wrapper.hpp" + +#include +#include +#include +#include + +class Container; + +template +class BindingBuilder +{ +public: + explicit BindingBuilder(Container *container); + + template >> + void to(); + + void to_factory(Interface func); + +private: + Container *_container; +}; + +template +struct is_func : public std::false_type // NOLINT(readability-identifier-naming) +{ +}; + +template +struct is_func> : public std::true_type +{ +}; + +class Container +{ +public: + Container() = default; + + template + BindingBuilder bind(); + + template >> + std::shared_ptr get() const; + + /* + template && + std::is_invocable_v>> + Interface get() const; + */ + + template ::value>> + Interface get() const; + + std::unordered_map, ObjectTypeHasher> + bindings; +}; + +#include "container.tpp" -- cgit v1.2.3-18-g5258