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.tpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/DI/container.tpp b/src/DI/container.tpp
index 21bf81a..e5bf7f7 100644
--- a/src/DI/container.tpp
+++ b/src/DI/container.tpp
@@ -5,6 +5,8 @@
#include "function_wrapper.hpp"
#include "object_wrapper.hpp"
+#include <iostream>
+
template <class Interface>
BindingBuilder<Interface>::BindingBuilder(Container *container) : _container(container)
{
@@ -37,8 +39,18 @@ BindingBuilder<Interface> Container::bind()
template <class Interface, class>
std::shared_ptr<Interface> Container::get() const
{
+ ObjectType<Interface> interface_type;
+
+ if (bindings.count(interface_type) == 0)
+ {
+ std::cerr
+ << "Error: Tried to get a item from the container using unbound interface '"
+ << interface_type.name() << "'" << std::endl;
+ exit(EXIT_FAILURE);
+ }
+
auto wrapper = std::dynamic_pointer_cast<IWrapper<std::shared_ptr<Interface>>>(
- bindings.at(ObjectType<Interface>()));
+ bindings.at(interface_type));
return wrapper->get();
}