diff --git a/src/ui/util/ioc/ioccontainer.cpp b/src/ui/util/ioc/ioccontainer.cpp index c2cfdf26..dc150a15 100644 --- a/src/ui/util/ioc/ioccontainer.cpp +++ b/src/ui/util/ioc/ioccontainer.cpp @@ -56,16 +56,18 @@ void IocContainer::autoDeleteAll() } } -void IocContainer::setUp(int typeId) +IocService *IocContainer::setUp(int typeId) { - const quint8 flags = m_objectFlags[typeId]; - if ((flags & (IsService | WasSetUp)) != IsService) - return; - - m_objectFlags[typeId] = (flags | WasSetUp); - IocService *obj = resolveService(typeId); - obj->setUp(); + + const quint8 flags = m_objectFlags[typeId]; + if ((flags & (IsService | WasSetUp)) == IsService) { + m_objectFlags[typeId] = (flags | WasSetUp); + + obj->setUp(); + } + + return obj; } void IocContainer::tearDown(int typeId) diff --git a/src/ui/util/ioc/ioccontainer.h b/src/ui/util/ioc/ioccontainer.h index 03181db1..86c43f3c 100644 --- a/src/ui/util/ioc/ioccontainer.h +++ b/src/ui/util/ioc/ioccontainer.h @@ -66,17 +66,16 @@ public: return static_cast(resolveService(getTypeId())); } - void setUpAll(); - void tearDownAll(); - void autoDeleteAll(); - template inline constexpr T *setUpDependency() { - setUp(getTypeId()); - return resolve(); + return static_cast(setUp(getTypeId())); } + void setUpAll(); + void tearDownAll(); + void autoDeleteAll(); + bool pinToThread(); inline static IocContainer *getPinned() @@ -101,7 +100,7 @@ private: return static_cast(resolveObject(typeId)); } - void setUp(int typeId); + IocService *setUp(int typeId); void tearDown(int typeId); void autoDelete(int typeId); @@ -124,9 +123,7 @@ constexpr auto IoCPinned = IocContainer::getPinned; template inline static T *IoC() { - const IocContainer *container = IoCPinned(); - Q_ASSERT(container); - return container->resolve(); + return IoCPinned()->resolve(); } #endif // IOCCONTAINER_H