From 40c828455d094854d9e531fc7dd0d1a0244957b7 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 29 Mar 2022 19:29:08 +0200 Subject: refactor: make container use concepts --- src/DI/container.hpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/DI/container.hpp') 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 #include -#include #include class Container; @@ -16,8 +17,8 @@ class BindingBuilder public: explicit BindingBuilder(Container *container) noexcept; - template >> + template + requires std::derived_from void to() noexcept; void to_factory(Interface func) noexcept; @@ -31,17 +32,24 @@ class Container public: Container() noexcept = default; + template + using Ptr = std::shared_ptr; + template auto bind() noexcept -> BindingBuilder; - template >> - auto get() const noexcept -> std::shared_ptr; + template + requires Abstract + auto get() const noexcept -> Ptr; - template >> + template + requires Function auto get() const noexcept -> Interface; - std::unordered_map, ObjectTypeHasher> - bindings; + void add(BaseObjectType type, const Ptr &wrapper) noexcept; + +private: + std::unordered_map, ObjectTypeHasher> _bindings; }; #include "container.tpp" -- cgit v1.2.3-18-g5258