diff options
Diffstat (limited to 'src/DI/container.hpp')
-rw-r--r-- | src/DI/container.hpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/DI/container.hpp b/src/DI/container.hpp index 83f24ae..0c0155c 100644 --- a/src/DI/container.hpp +++ b/src/DI/container.hpp @@ -1,11 +1,12 @@ #pragma once #include "DI/interfaces/wrapper.hpp" + +#include "DI/concepts.hpp" #include "DI/object_type.hpp" -#include "DI/type_traits.hpp" +#include <concepts> #include <memory> -#include <type_traits> #include <unordered_map> class Container; @@ -16,8 +17,8 @@ class BindingBuilder public: explicit BindingBuilder(Container *container) noexcept; - template <class ObjectImpl, - class = std::enable_if_t<std::is_base_of_v<Interface, ObjectImpl>>> + template <typename Impl> + requires std::derived_from<Impl, Interface> void to() noexcept; void to_factory(Interface func) noexcept; @@ -31,17 +32,24 @@ class Container public: Container() noexcept = default; + template <typename Type> + using Ptr = std::shared_ptr<Type>; + template <class Interface> auto bind() noexcept -> BindingBuilder<Interface>; - template <class Interface, class = std::enable_if_t<std::is_abstract_v<Interface>>> - auto get() const noexcept -> std::shared_ptr<Interface>; + template <class Interface> + requires Abstract<Interface> + auto get() const noexcept -> Ptr<Interface>; - template <typename Interface, typename = std::enable_if_t<is_func_v<Interface>>> + template <typename Interface> + requires Function<Interface> auto get() const noexcept -> Interface; - std::unordered_map<BaseObjectType, std::shared_ptr<IGenericWrapper>, ObjectTypeHasher> - bindings; + void add(BaseObjectType type, const Ptr<IGenericWrapper> &wrapper) noexcept; + +private: + std::unordered_map<BaseObjectType, Ptr<IGenericWrapper>, ObjectTypeHasher> _bindings; }; #include "container.tpp" |