@@ -106,6 +106,25 @@ class CoreContext:
106106 // / </summary>
107107 static std::shared_ptr<CoreContext> GetGlobal (void );
108108
109+ // / <summary>
110+ // / Represents a single entry, together with any deferred elements waiting on the satisfaction of this entry
111+ // / </summary>
112+ struct MemoEntry {
113+ MemoEntry (void ) :
114+ pFirst (nullptr )
115+ {}
116+
117+ // The first deferrable autowiring which requires this type, if one exists:
118+ DeferrableAutowiring* pFirst;
119+
120+ // A back reference to the concrete type from which this memo was generated:
121+ const ObjectTraits* pObjTraits;
122+
123+ // Once this memo entry is satisfied, this will contain the AnySharedPointer instance that performs
124+ // the satisfaction
125+ AnySharedPointer m_value;
126+ };
127+
109128protected:
110129 // A pointer to the parent context
111130 const std::shared_ptr<CoreContext> m_pParent;
@@ -133,22 +152,6 @@ class CoreContext:
133152 typedef std::unordered_map<std::type_index, std::list<BoltBase*>> t_contextNameListeners;
134153 t_contextNameListeners m_nameListeners;
135154
136- // / <summary>
137- // / Represents a single entry, together with any deferred elements waiting on the satisfaction of this entry
138- // / </summary>
139- struct MemoEntry {
140- MemoEntry (void ) :
141- pFirst (nullptr )
142- {}
143-
144- // The first deferrable autowiring which requires this type, if one exists:
145- DeferrableAutowiring* pFirst;
146-
147- // Once this memo entry is satisfied, this will contain the AnySharedPointer instance that performs
148- // the satisfaction
149- AnySharedPointer m_value;
150- };
151-
152155 // / <summary>
153156 // / A proxy context member that knows how to create a factory for a particular type
154157 // / </summary>
@@ -257,7 +260,7 @@ class CoreContext:
257260 // / <summary>
258261 // / Invokes all deferred autowiring fields, generally called after a new member has been added
259262 // / </summary>
260- void UpdateDeferredElements (std::unique_lock<std::mutex>&& lk, const std::shared_ptr<Object> & entry);
263+ void UpdateDeferredElements (std::unique_lock<std::mutex>&& lk, const ObjectTraits & entry);
261264
262265 // / <summary>
263266 // / Adds the named event receiver to the collection of known receivers
@@ -427,6 +430,19 @@ class CoreContext:
427430 // / </returns>
428431 std::shared_ptr<CoreContext> NextSibling (void ) const ;
429432
433+ // / <returns>
434+ // / The type identifier of the specified type identifier
435+ // / </returns>
436+ // / <remarks>
437+ // / The returned type structure will be the actual type of the specified object as defined at the time of
438+ // / injection. In the case of a static factory new or AutoFactory new, this type will be the type of the
439+ // / interface. All other members are the concrete type actually injected, as opposed to the type unifier
440+ // / for that type.
441+ // /
442+ // / This method will throw an exception if the passed shared pointer is not strictly a member of this context
443+ // / </remarks>
444+ const std::type_info& GetAutoTypeId (const AnySharedPointer& ptr) const ;
445+
430446 // / <summary>
431447 // / Creation helper routine
432448 // / </summary>
@@ -505,15 +521,21 @@ class CoreContext:
505521 // Add this type to the TypeRegistry
506522 (void ) RegType<T>::r;
507523
508- // First see if the object has already been injected:
509- std::shared_ptr<typename CreationRules::TActual> retVal;
510- FindByType (retVal);
511- if (retVal)
512- return std::static_pointer_cast<T>(retVal);
524+ // First see if the base object type has already been injected. This is also necessary to
525+ // ensure that a memo slot is created for the type by itself, in cases where the injected
526+ // member does not inherit Object and this member is eventually satisfied by one that does.
527+ {
528+ std::shared_ptr<T> pure;
529+ FindByType (pure);
530+ if (pure)
531+ return pure;
532+ }
513533
514534 // We must make ourselves current for the remainder of this call:
515535 CurrentContextPusher pshr (shared_from_this ());
516- retVal.reset (CreationRules::New (*this , std::forward<Args>(args)...));
536+ std::shared_ptr<typename CreationRules::TActual> retVal (
537+ CreationRules::New (*this , std::forward<Args>(args)...)
538+ );
517539
518540 // AutoInit if sensible to do so:
519541 CallAutoInit (*retVal, has_autoinit<T>());
0 commit comments