diff --git a/research/try.cpp b/research/try.cpp index 59c87e721..04483dc2c 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -174,16 +174,44 @@ InstanceHolder Depend::singleton; ///////////////////////////////////////////////////////Configuration +using std::move; + + template class DependInject { + using Factory = typename Depend::Factory; public: + static void + installFactory (Factory&& otherFac) + { + ClassLock guard; + if (Depend::instance) + throw error::Logic("Attempt to reconfigure dependency injection after the fact. " + "The previously installed factory (typically Singleton) was already used." + , error::LUMIERA_ERROR_LIFECYCLE); + Depend::factory = move (otherFac); + } + + static void + disableFactory() + { + ClassLock guard; + Depend::factory = Depend::disabledFactory; + } + + template - void + static void useSingleton() { - UNIMPLEMENTED ("reconfigure to plant a singleton of subclass type"); + static InstanceHolder singleton; + installFactory ([&]() + { + disableFactory(); + return singleton.buildInstance(); + }); } template @@ -225,7 +253,7 @@ struct Dummy : Dum { Dummy() { checksum += N; } - ~Dummy() { checksum -= N; } + ~Dummy() { checksum -= N; cout << "~Dummy<"<"< dumm; -// Depend::factory = [](){ return nullptr; }; + DependInject::useSingleton>(); SHOW_EXPR( dumm().probe() ); + SHOW_EXPR( checksum ); + VERIFY_ERROR (LIFECYCLE, DependInject::useSingleton>() ); + SHOW_EXPR( Depend{}().probe() ); + SHOW_EXPR( checksum ); cout << "\n.gulp.\n"; diff --git a/wiki/renderengine.html b/wiki/renderengine.html index 71f34438c..a715012ea 100644 --- a/wiki/renderengine.html +++ b/wiki/renderengine.html @@ -1927,7 +1927,7 @@ As we don't have a Prolog interpreter on board yet, we utilize a mock store with {{{default(Obj)}}} is a predicate expressing that the object {{{Obj}}} can be considered the default setup under the given conditions. Using the //default// can be considered as a shortcut for actually finding an exact and unique solution. The latter would require to specify all sorts of detailed properties up to the point where only one single object can satisfy all conditions. On the other hand, leaving some properties unspecified would yield a set of solutions (and the user code issuing the query had to provide means for selecting one solution from this set). Just falling back on the //default// means that the user code actually doesn't care for any additional properties (as long as the properties he //does// care for are satisfied). Nothing is said specifically on //how//&nbsp; this default gets configured; actually there can be rules //somewhere,// and, additionally, anything encountered once while asking for a default can be re-used as default under similar circumstances. &rarr; [[implementing defaults|DefaultsImplementation]] -
+
//Access point to dependencies by-name.//
 In the Lumiera code base, we refrain from building or using a full-blown Dependency Injection Container. A lot of FUD has been spread regarding Dependency Injection and Singletons, to the point that a majority of developers confuses and conflates the ~Inversion-of-Control principle (which is essential) with the use of a ~DI-Container. Today, you can not even mention the word "Singleton" without everyone yelling out "Evil! Evil!" -- while most of these people just feel comfortable living in the annotation hell.
 
@@ -1950,7 +1950,7 @@ Deliberately, we do not enforce global consistency statically (since that would
 :access the singleton instance as {{{theBla().doIt();}}}
 ;singleton subclass
 :{{{DependInject<Blah>::useSingleton<SubBlah>() }}}
-:causes the dependency factory {{{Depend<Bla>}}} to create a {{{SubBla}}} singleton instance
+:causes the dependency factory {{{Depend<Bla>}}} to create a {{{SubBla}}} singleton instance from now on
 ;attach to service
 :{{{DependInject<Blah>::ServiceInstance<SubBlah> service{p1, p2, p3}}}}
 :* build and manage an instance of {{{SubBlah}}} in heap memory immediately (not lazily)
diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm
index 5bf514860..a0bf63ce4 100644
--- a/wiki/thinkPad.ichthyo.mm
+++ b/wiki/thinkPad.ichthyo.mm
@@ -26783,19 +26783,27 @@
 
 
 
-
-
-
+
+
+
 
 
 
 
 
 
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
 
 
 
@@ -26955,13 +26963,15 @@
 
 
 
-
+
+
 
 
 
 
 
-
+
+
 
 
 
@@ -26985,7 +26995,7 @@
 
 
 
-
+
 
 
 
@@ -27071,8 +27081,8 @@
 
 
 
-
-
+
+