From 845ff3d141553d24d4572738101fce948bf40e67 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 14 Jun 2022 18:31:39 +0200 Subject: refactor!: rename Container to DIContainer --- examples/basic/src/bootstrap.cpp | 16 ++++++++-------- examples/basic/src/bootstrap.hpp | 2 +- include/yacppdic/auto_wirable.hpp | 6 +++--- include/yacppdic/container.hpp | 15 +++++++++------ include/yacppdic/detail/auto_wirable-impl.hpp | 6 +++--- include/yacppdic/detail/container-impl.hpp | 12 ++++++------ .../yacppdic/detail/internal/wrapper/object_wrapper.hpp | 6 ++++-- test/container.test.cpp | 2 +- 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().to(); - container.bind().to(); - container.bind().to(); + di_container.bind().to(); + di_container.bind().to(); + di_container.bind().to(); - container.bind() + di_container.bind() .to_factory( []() { @@ -29,7 +29,7 @@ auto bootstrap() -> yacppdic::Container ) .when_tagged(); - container.bind() + di_container.bind() .to_factory( []() { @@ -38,5 +38,5 @@ auto bootstrap() -> yacppdic::Container ) .when_tagged(); - 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 -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 class AutoWirable { public: - static auto resolve(const Container &container) noexcept + static auto resolve(const DIContainer &container) noexcept -> std::unique_ptr; private: template requires IsTagged - static auto _get_dependency(const Container &container) noexcept; + static auto _get_dependency(const DIContainer &container) noexcept; template - 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 class BindingBuilder; @@ -63,18 +63,21 @@ public: auto to_factory(FactoryFunc factory) noexcept -> BindingWhen; 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 auto bind() noexcept -> BindingBuilder; 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 auto AutoWirable::resolve( - const Container &container + const DIContainer &container ) noexcept -> std::unique_ptr { return std::make_unique(_get_dependency(container)...); @@ -17,7 +17,7 @@ template template requires IsTagged auto AutoWirable::_get_dependency( - const Container &container + const DIContainer &container ) noexcept { return container.get_tagged(); @@ -26,7 +26,7 @@ auto AutoWirable::_get_dependency( template template auto AutoWirable::_get_dependency( - const Container &container + const DIContainer &container ) noexcept { return container.get(); 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::when_tagged() noexcept template BindingBuilder::BindingBuilder( - Container &container, + DIContainer &container, internal::Bindings &bindings ) noexcept : _container(container), _bindings(bindings) @@ -75,14 +75,14 @@ auto BindingBuilder::to_factory(FactoryFunc factory) noexcept } template -auto Container::bind() noexcept -> BindingBuilder +auto DIContainer::bind() noexcept -> BindingBuilder { return BindingBuilder(*this, _bindings); } template requires Abstract -auto Container::get() const noexcept -> std::unique_ptr +auto DIContainer::get() const noexcept -> std::unique_ptr { auto object_identifier = internal::ObjectIdentifier::create(); @@ -103,7 +103,7 @@ auto Container::get() const noexcept -> std::unique_ptr template requires IsFactory -auto Container::get() const noexcept -> AFactory +auto DIContainer::get() const noexcept -> AFactory { auto object_identifier = internal::ObjectIdentifier::create(); @@ -123,7 +123,7 @@ auto Container::get() const noexcept -> AFactory template requires Abstract -auto Container::get_tagged() const noexcept -> std::unique_ptr +auto DIContainer::get_tagged() const noexcept -> std::unique_ptr { auto object_identifier = internal::ObjectIdentifier::create(); @@ -145,7 +145,7 @@ auto Container::get_tagged() const noexcept -> std::unique_ptr template requires IsFactory -auto Container::get_tagged() const noexcept -> AFactory +auto DIContainer::get_tagged() const noexcept -> AFactory { auto object_identifier = internal::ObjectIdentifier::create(); 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 ObjectWrapper : public IWrapper> { 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 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 { -- cgit v1.2.3-18-g5258