Skip to content

Commit

Permalink
feature: FindParent Override
Browse files Browse the repository at this point in the history
  • Loading branch information
gtg092x committed Jul 11, 2024
1 parent ce3e6a7 commit 583d021
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,24 @@ void InstallTo(IContainerBuilder builder)
EntryPointsBuilder.EnsureDispatcherRegistered(builder);
}

protected virtual LifetimeScope FindParent() => null;

LifetimeScope GetRuntimeParent()
{
if (IsRoot) return null;

if (parentReference.Object != null)
return parentReference.Object;

// Find via implementation
var implParent = FindParent();
if (implParent != null)
{
if (parentReference.Type != null && parentReference.Type != implParent.GetType()) {
UnityEngine.Debug.LogWarning($"FindParent returned {implParent.GetType()} but parent reference type is {parentReference.Type}. This may be unintentional.");
}
return implParent;
}

// Find in scene via type
if (parentReference.Type != null && parentReference.Type != GetType())
Expand Down

0 comments on commit 583d021

Please sign in to comment.