aboutsummaryrefslogtreecommitdiff
path: root/src/DI/container.tpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/DI/container.tpp')
-rw-r--r--src/DI/container.tpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/DI/container.tpp b/src/DI/container.tpp
index 54b09c6..13397bc 100644
--- a/src/DI/container.tpp
+++ b/src/DI/container.tpp
@@ -15,23 +15,25 @@ BindingBuilder<Interface>::BindingBuilder(Container *container) noexcept
template <typename Interface>
template <typename Impl>
-requires std::derived_from<Impl, Interface>
+requires Abstract<Interface> && std::derived_from<Impl, Interface>
void BindingBuilder<Interface>::to() noexcept
{
using Wrapper = ObjectWrapper<Interface, Impl>;
- auto wrapper = Container::Ptr<Wrapper>(new Wrapper(*_container));
+ auto wrapper = Container::WrapperPtr<Wrapper>(new Wrapper(*_container));
_container->add(ObjectType<Interface>(),
std::dynamic_pointer_cast<IGenericWrapper>(wrapper));
}
template <typename Interface>
-void BindingBuilder<Interface>::to_factory(Interface func) noexcept
+template <typename FactoryFunc>
+requires IsFactory<Interface> && std::constructible_from<Interface, FactoryFunc>
+void BindingBuilder<Interface>::to_factory(FactoryFunc factory) noexcept
{
using Wrapper = FunctionWrapper<Interface>;
- auto wrapper = Container::Ptr<Wrapper>(new Wrapper(func));
+ auto wrapper = Container::WrapperPtr<Wrapper>(new Wrapper(factory));
_container->add(ObjectType<Interface>(),
std::dynamic_pointer_cast<IGenericWrapper>(wrapper));
@@ -45,7 +47,7 @@ auto Container::bind() noexcept -> BindingBuilder<Interface>
template <typename Interface>
requires Abstract<Interface>
-auto Container::get() const noexcept -> Ptr<Interface>
+auto Container::get() const noexcept -> std::unique_ptr<Interface>
{
ObjectType<Interface> interface_type;
@@ -57,18 +59,18 @@ auto Container::get() const noexcept -> Ptr<Interface>
exit(EXIT_FAILURE);
}
- auto wrapper =
- std::dynamic_pointer_cast<IWrapper<Ptr<Interface>>>(_bindings.at(interface_type));
+ auto wrapper = std::dynamic_pointer_cast<IWrapper<std::unique_ptr<Interface>>>(
+ _bindings.at(interface_type));
return wrapper->get();
}
-template <typename Interface>
-requires Function<Interface>
-auto Container::get() const noexcept -> Interface
+template <typename AFactory>
+requires IsFactory<AFactory>
+auto Container::get() const noexcept -> AFactory
{
- auto wrapper = std::dynamic_pointer_cast<IWrapper<Interface>>(
- _bindings.at(ObjectType<Interface>()));
+ auto wrapper = std::dynamic_pointer_cast<IWrapper<AFactory>>(
+ _bindings.at(ObjectType<AFactory>()));
return wrapper->get();
}