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.hpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/DI/container.hpp b/src/DI/container.hpp
index 0c0155c..d5f52b8 100644
--- a/src/DI/container.hpp
+++ b/src/DI/container.hpp
@@ -3,9 +3,11 @@
#include "DI/interfaces/wrapper.hpp"
#include "DI/concepts.hpp"
+#include "DI/factory.hpp"
#include "DI/object_type.hpp"
#include <concepts>
+#include <functional>
#include <memory>
#include <unordered_map>
@@ -18,10 +20,12 @@ public:
explicit BindingBuilder(Container *container) noexcept;
template <typename Impl>
- requires std::derived_from<Impl, Interface>
+ requires Abstract<Interface> && std::derived_from<Impl, Interface>
void to() noexcept;
- void to_factory(Interface func) noexcept;
+ template <typename FactoryFunc>
+ requires IsFactory<Interface> && std::constructible_from<Interface, FactoryFunc>
+ void to_factory(FactoryFunc factory) noexcept;
private:
Container *_container;
@@ -33,23 +37,24 @@ public:
Container() noexcept = default;
template <typename Type>
- using Ptr = std::shared_ptr<Type>;
+ using WrapperPtr = std::shared_ptr<Type>;
template <class Interface>
auto bind() noexcept -> BindingBuilder<Interface>;
template <class Interface>
requires Abstract<Interface>
- auto get() const noexcept -> Ptr<Interface>;
+ auto get() const noexcept -> std::unique_ptr<Interface>;
- template <typename Interface>
- requires Function<Interface>
- auto get() const noexcept -> Interface;
+ template <typename AFactory>
+ requires IsFactory<AFactory>
+ auto get() const noexcept -> AFactory;
- void add(BaseObjectType type, const Ptr<IGenericWrapper> &wrapper) noexcept;
+ void add(BaseObjectType type, const WrapperPtr<IGenericWrapper> &wrapper) noexcept;
private:
- std::unordered_map<BaseObjectType, Ptr<IGenericWrapper>, ObjectTypeHasher> _bindings;
+ std::unordered_map<BaseObjectType, WrapperPtr<IGenericWrapper>, ObjectTypeHasher>
+ _bindings;
};
#include "container.tpp"