diff --git a/src/lib/depend-inject.hpp b/src/lib/depend-inject.hpp index 67ae8874d..e667af3b1 100644 --- a/src/lib/depend-inject.hpp +++ b/src/lib/depend-inject.hpp @@ -168,7 +168,7 @@ namespace lib { static void useSingleton() { - useSingleton ([]{ return new SUB{}; }); + installFactory ([]{ return & Depend{}(); }); } /** configure dependency-injection for type SRV to manage a subclass singleton, @@ -357,10 +357,11 @@ namespace lib { static Factory buildCustomSingleton (FUN&& ctor) { - static InstanceHolder singleton; + static std::unique_ptr singleton; return ([ctor]() // copy of ctor in the closure { - return singleton.buildInstance (ctor); + singleton.reset (ctor()); + return singleton.get(); }); } diff --git a/tests/library/dependency-factory-test.cpp b/tests/library/dependency-factory-test.cpp index 29fc1d42c..f0679b6bf 100644 --- a/tests/library/dependency-factory-test.cpp +++ b/tests/library/dependency-factory-test.cpp @@ -78,6 +78,10 @@ namespace test{ struct SubSubSub : SubSub { }; + + struct SubSubDub + : SubSub + { }; } @@ -148,7 +152,7 @@ namespace test{ SubSub& oSub = otherSpecialAccessor(); CHECK ( INSTANCEOF (SubSubSub, &oSub)); - Depend yetAnotherSpecialAccessor; + Depend yetAnotherSpecialAccessor; SubSub& yetAnotherInstance = yetAnotherSpecialAccessor(); CHECK ( INSTANCEOF (SubSubSub, &yetAnotherInstance)); @@ -161,26 +165,18 @@ namespace test{ void verify_customFactory() { - DependInject::useSingleton (customFactoryFunction); + DependInject::useSingleton (customFactoryFunction); - Depend customisedAccessor; - Depend otherSpecialAccessor; + Depend customised; - SubSub& oSub = otherSpecialAccessor(); - SubSubSub& oSubS = customisedAccessor(); - - CHECK (!isSameObject (oSub, oSubS)); - CHECK ( INSTANCEOF (SubSubSub, &oSub)); - CHECK ( INSTANCEOF (SubSubSub, &oSubS)); - - CHECK (oSub.instanceID_ != oSubS.instanceID_); - CHECK (MAX_ID + 10 == oSubS.instanceID_); + CHECK ( INSTANCEOF (SubSubDub, &customised())); + CHECK (MAX_ID + 10 == customised().instanceID_); } - static SubSubSub* + static SubSubDub* customFactoryFunction (void) { - SubSubSub* specialInstance = new SubSubSub; + SubSubDub* specialInstance = new SubSubDub; specialInstance->instanceID_ = MAX_ID + 10; return specialInstance; } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 3e2143b80..412f893c8 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -27697,6 +27697,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ ...man könnte ihn aber genausogut auch machen. +

+

+ Das Argument ist: wenn wir kaskadierend aufrufen, dann ist das Ergebnis in jedem Fall korrekt, +

+

+ und wird auch durch das Installieren dieses (zweiten) Zuganges in keinster Weise beeinträchtigt. +

+

+ Sollte Depend<SUB> bereits instantiiert sein, dann auch gut. +

+

+ Der kaskadierende Aufruf liest dann einfach dessen Instanz-Pointer +

+ + +
+
+
+ + + + + + + + + + +

+ hier notwendig, weil wir eine neue Factory-Funktion ablegen. +

+

+ Das könnte mit dem Factory-Management einer bereits installierten Konfiguration kollidieren +

+ + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -27893,6 +27998,10 @@ + + + +