If an instance of the requested type already exists on this
Context, that instance will be returned; otherwise, a new one will be lazily created. This method implements the "safe singleton" pattern discussed in the remarks on the
Context. While the name "GetOrCreate" is used to clarify that the requested instance
may be created during this call, this method should really only be thought of as an accessor with any instantiation that may or may not happen being simply an irrelevant implementation detail. Ideally, you should think of Context-local singletons as aspects of the
Context itself rather than as separate instances which can be created and destroyed independently. Adhering to this thinking will ensure that order-of-operations and independent lifecycles do not complicate the usage of
Context. As long as the
Context merely exists,
all singletons on it can
always be accessed identically using GetOrCreateSingleton; all other considerations are the purview of the singletons themselves.
OthersTThe type of the singleton to be retrieved
ReturnsA Context-local singleton of the requested type