aboutsummaryrefslogtreecommitdiff
path: root/src/DI/container.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/DI/container.hpp')
-rw-r--r--src/DI/container.hpp65
1 files changed, 65 insertions, 0 deletions
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 <functional>
+#include <memory>
+#include <type_traits>
+#include <unordered_map>
+
+class Container;
+
+template <typename Interface>
+class BindingBuilder
+{
+public:
+ explicit BindingBuilder(Container *container);
+
+ template <class ObjectImpl,
+ class = std::enable_if_t<std::is_base_of_v<Interface, ObjectImpl>>>
+ void to();
+
+ void to_factory(Interface func);
+
+private:
+ Container *_container;
+};
+
+template <typename Satan>
+struct is_func : public std::false_type // NOLINT(readability-identifier-naming)
+{
+};
+
+template <typename Satan, typename... Args>
+struct is_func<std::function<Satan(Args...)>> : public std::true_type
+{
+};
+
+class Container
+{
+public:
+ Container() = default;
+
+ template <class Interface>
+ BindingBuilder<Interface> bind();
+
+ template <class Interface, class = std::enable_if_t<std::is_abstract_v<Interface>>>
+ std::shared_ptr<Interface> get() const;
+
+ /*
+ template <typename Interface,
+ typename = std::enable_if_t<
+ !std::is_abstract_v<Interface> &&
+ std::is_invocable_v<Interface, typename Interface::argument_type>>>
+ Interface get() const;
+ */
+
+ template <typename Interface, typename = std::enable_if_t<is_func<Interface>::value>>
+ Interface get() const;
+
+ std::unordered_map<BaseObjectType, std::shared_ptr<IGenericWrapper>, ObjectTypeHasher>
+ bindings;
+};
+
+#include "container.tpp"