aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-14 18:31:39 +0200
committerHampusM <hampus@hampusmat.com>2022-06-14 18:31:39 +0200
commit845ff3d141553d24d4572738101fce948bf40e67 (patch)
treefff2a606ba04bc4526e69df0b7b1e3d28fdf63b3
parent9d50e72892f84c602df3c328259cdfdd325bca12 (diff)
refactor!: rename Container to DIContainer
-rw-r--r--examples/basic/src/bootstrap.cpp16
-rw-r--r--examples/basic/src/bootstrap.hpp2
-rw-r--r--include/yacppdic/auto_wirable.hpp6
-rw-r--r--include/yacppdic/container.hpp15
-rw-r--r--include/yacppdic/detail/auto_wirable-impl.hpp6
-rw-r--r--include/yacppdic/detail/container-impl.hpp12
-rw-r--r--include/yacppdic/detail/internal/wrapper/object_wrapper.hpp6
-rw-r--r--test/container.test.cpp2
8 files changed, 35 insertions, 30 deletions
diff --git a/examples/basic/src/bootstrap.cpp b/examples/basic/src/bootstrap.cpp
index 104cf51..507cde7 100644
--- a/examples/basic/src/bootstrap.cpp
+++ b/examples/basic/src/bootstrap.cpp
@@ -12,15 +12,15 @@
#include "hero.hpp"
#include "sword.hpp"
-auto bootstrap() -> yacppdic::Container
+auto bootstrap() -> yacppdic::DIContainer
{
- auto container = yacppdic::Container();
+ auto di_container = yacppdic::DIContainer();
- container.bind<IHero>().to<Hero>();
- container.bind<IWeapon>().to<Sword>();
- container.bind<IEnemyCreator>().to<EnemyCreator>();
+ di_container.bind<IHero>().to<Hero>();
+ di_container.bind<IWeapon>().to<Sword>();
+ di_container.bind<IEnemyCreator>().to<EnemyCreator>();
- container.bind<IEnemyFactory>()
+ di_container.bind<IEnemyFactory>()
.to_factory(
[]()
{
@@ -29,7 +29,7 @@ auto bootstrap() -> yacppdic::Container
)
.when_tagged<SMALL_ENEMY_TAG>();
- container.bind<IEnemyFactory>()
+ di_container.bind<IEnemyFactory>()
.to_factory(
[]()
{
@@ -38,5 +38,5 @@ auto bootstrap() -> yacppdic::Container
)
.when_tagged<BIG_ENEMY_TAG>();
- return container;
+ return di_container;
}
diff --git a/examples/basic/src/bootstrap.hpp b/examples/basic/src/bootstrap.hpp
index 9febbd9..964a3d7 100644
--- a/examples/basic/src/bootstrap.hpp
+++ b/examples/basic/src/bootstrap.hpp
@@ -2,4 +2,4 @@
#include <yacppdic/container.hpp>
-auto bootstrap() -> yacppdic::Container;
+auto bootstrap() -> yacppdic::DIContainer;
diff --git a/include/yacppdic/auto_wirable.hpp b/include/yacppdic/auto_wirable.hpp
index ecd240b..288068a 100644
--- a/include/yacppdic/auto_wirable.hpp
+++ b/include/yacppdic/auto_wirable.hpp
@@ -12,16 +12,16 @@ template <typename Interface, typename ObjectImpl, typename... Dependencies>
class AutoWirable
{
public:
- static auto resolve(const Container &container) noexcept
+ static auto resolve(const DIContainer &container) noexcept
-> std::unique_ptr<Interface>;
private:
template <typename Dependency>
requires IsTagged<Dependency>
- static auto _get_dependency(const Container &container) noexcept;
+ static auto _get_dependency(const DIContainer &container) noexcept;
template <typename Dependency>
- static auto _get_dependency(const Container &container) noexcept;
+ static auto _get_dependency(const DIContainer &container) noexcept;
};
} // namespace yacppdic
diff --git a/include/yacppdic/container.hpp b/include/yacppdic/container.hpp
index 6191fed..9e5237c 100644
--- a/include/yacppdic/container.hpp
+++ b/include/yacppdic/container.hpp
@@ -26,7 +26,7 @@ using Bindings = std::unordered_map<ObjectIdentifier, WrapperPtr<IGenericWrapper
} // namespace internal
-class Container;
+class DIContainer;
template <typename Interface>
class BindingBuilder;
@@ -63,18 +63,21 @@ public:
auto to_factory(FactoryFunc factory) noexcept -> BindingWhen<Interface>;
private:
- Container &_container;
+ DIContainer &_container;
internal::Bindings &_bindings;
- explicit BindingBuilder(Container &container, internal::Bindings &bindings) noexcept;
+ explicit BindingBuilder(
+ DIContainer &container,
+ internal::Bindings &bindings
+ ) noexcept;
- friend Container;
+ friend DIContainer;
};
-class Container
+class DIContainer
{
public:
- Container() noexcept = default;
+ DIContainer() noexcept = default;
template <class Interface>
auto bind() noexcept -> BindingBuilder<Interface>;
diff --git a/include/yacppdic/detail/auto_wirable-impl.hpp b/include/yacppdic/detail/auto_wirable-impl.hpp
index a6b1506..13d2cdf 100644
--- a/include/yacppdic/detail/auto_wirable-impl.hpp
+++ b/include/yacppdic/detail/auto_wirable-impl.hpp
@@ -7,7 +7,7 @@ namespace yacppdic
template <typename Interface, typename ObjectImpl, typename... Dependencies>
auto AutoWirable<Interface, ObjectImpl, Dependencies...>::resolve(
- const Container &container
+ const DIContainer &container
) noexcept -> std::unique_ptr<Interface>
{
return std::make_unique<ObjectImpl>(_get_dependency<Dependencies>(container)...);
@@ -17,7 +17,7 @@ template <typename Interface, typename ObjectImpl, typename... Dependencies>
template <typename Dependency>
requires IsTagged<Dependency>
auto AutoWirable<Interface, ObjectImpl, Dependencies...>::_get_dependency(
- const Container &container
+ const DIContainer &container
) noexcept
{
return container.get_tagged<typename Dependency::Target, Dependency::get_tag()>();
@@ -26,7 +26,7 @@ auto AutoWirable<Interface, ObjectImpl, Dependencies...>::_get_dependency(
template <typename Interface, typename ObjectImpl, typename... Dependencies>
template <typename Dependency>
auto AutoWirable<Interface, ObjectImpl, Dependencies...>::_get_dependency(
- const Container &container
+ const DIContainer &container
) noexcept
{
return container.get<Dependency>();
diff --git a/include/yacppdic/detail/container-impl.hpp b/include/yacppdic/detail/container-impl.hpp
index 5d74616..3624031 100644
--- a/include/yacppdic/detail/container-impl.hpp
+++ b/include/yacppdic/detail/container-impl.hpp
@@ -34,7 +34,7 @@ void BindingWhen<Interface>::when_tagged() noexcept
template <typename Interface>
BindingBuilder<Interface>::BindingBuilder(
- Container &container,
+ DIContainer &container,
internal::Bindings &bindings
) noexcept
: _container(container), _bindings(bindings)
@@ -75,14 +75,14 @@ auto BindingBuilder<Interface>::to_factory(FactoryFunc factory) noexcept
}
template <typename Interface>
-auto Container::bind() noexcept -> BindingBuilder<Interface>
+auto DIContainer::bind() noexcept -> BindingBuilder<Interface>
{
return BindingBuilder<Interface>(*this, _bindings);
}
template <typename Interface>
requires Abstract<Interface>
-auto Container::get() const noexcept -> std::unique_ptr<Interface>
+auto DIContainer::get() const noexcept -> std::unique_ptr<Interface>
{
auto object_identifier = internal::ObjectIdentifier::create<Interface>();
@@ -103,7 +103,7 @@ auto Container::get() const noexcept -> std::unique_ptr<Interface>
template <typename AFactory>
requires IsFactory<AFactory>
-auto Container::get() const noexcept -> AFactory
+auto DIContainer::get() const noexcept -> AFactory
{
auto object_identifier = internal::ObjectIdentifier::create<AFactory>();
@@ -123,7 +123,7 @@ auto Container::get() const noexcept -> AFactory
template <class Interface, Tag tag>
requires Abstract<Interface>
-auto Container::get_tagged() const noexcept -> std::unique_ptr<Interface>
+auto DIContainer::get_tagged() const noexcept -> std::unique_ptr<Interface>
{
auto object_identifier = internal::ObjectIdentifier::create<Interface, tag>();
@@ -145,7 +145,7 @@ auto Container::get_tagged() const noexcept -> std::unique_ptr<Interface>
template <typename AFactory, Tag tag>
requires IsFactory<AFactory>
-auto Container::get_tagged() const noexcept -> AFactory
+auto DIContainer::get_tagged() const noexcept -> AFactory
{
auto object_identifier = internal::ObjectIdentifier::create<AFactory, tag>();
diff --git a/include/yacppdic/detail/internal/wrapper/object_wrapper.hpp b/include/yacppdic/detail/internal/wrapper/object_wrapper.hpp
index f3c5e87..19bcf1a 100644
--- a/include/yacppdic/detail/internal/wrapper/object_wrapper.hpp
+++ b/include/yacppdic/detail/internal/wrapper/object_wrapper.hpp
@@ -13,12 +13,14 @@ template <class Interface, class ObjectImpl>
class ObjectWrapper : public IWrapper<std::unique_ptr<Interface>>
{
public:
- explicit ObjectWrapper(const Container &container) noexcept : _container(container) {}
+ explicit ObjectWrapper(const DIContainer &container) noexcept : _container(container)
+ {
+ }
[[nodiscard]] auto get() const noexcept -> std::unique_ptr<Interface> override;
private:
- const Container &_container;
+ const DIContainer &_container;
};
} // namespace yacppdic::internal
diff --git a/test/container.test.cpp b/test/container.test.cpp
index 54290ea..ec3e332 100644
--- a/test/container.test.cpp
+++ b/test/container.test.cpp
@@ -6,7 +6,7 @@
TEST(ContainerTest, BindAndGet)
{
- auto container = yacppdic::Container();
+ auto container = yacppdic::DIContainer();
class IObject
{