Skip to content

Commit

Permalink
Changed back to only initialize the global composition root in scenes…
Browse files Browse the repository at this point in the history
… that also have a scene composition root as discussed here:

https://groups.google.com/forum/#!msg/zenject/mD-v2IcVPlg/S--lMpl2CAAJ
  • Loading branch information
svermeulen committed Feb 4, 2016
1 parent a008c32 commit e7b4e8b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions Build/BinaryMetas/Zenject.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions UnityProject/Assets/Tests.meta

This file was deleted.

15 changes: 9 additions & 6 deletions UnityProject/Assets/Zenject/Source/Main/GlobalCompositionRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ public static GlobalCompositionRoot Instance
{
get
{
Assert.IsNotNull(_instance);
if (_instance == null)
{
_instance = new GameObject("Global Composition Root")
.AddComponent<GlobalCompositionRoot>();
_instance.Initialize();
}

return _instance;
}
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void GlobalMainEntryPoint()
public void EnsureIsInitialized()
{
_instance = new GameObject("Global Composition Root")
.AddComponent<GlobalCompositionRoot>();
_instance.Initialize();
// Do nothing - Initialize occurs in Instance property
}

void Initialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public override IFacade RootFacade

public void Awake()
{
// We always want to initialize GlobalCompositionRoot as early as possible
GlobalCompositionRoot.Instance.EnsureIsInitialized();

Assert.IsNull(Container);
Assert.IsNull(RootFacade);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public sealed class SceneDecoratorCompositionRoot : MonoBehaviour

public void Awake()
{
// We always want to initialize GlobalCompositionRoot as early as possible
GlobalCompositionRoot.Instance.EnsureIsInitialized();

_beforeInstallHooks = SceneCompositionRoot.BeforeInstallHooks;
SceneCompositionRoot.BeforeInstallHooks = null;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e7b4e8b

Please sign in to comment.