Created
May 16, 2019 08:04
-
-
Save monry/0e154b8abecdfeb80d4a6d210422b5b5 to your computer and use it in GitHub Desktop.
Reproduce code that `IInitializable.Initialize()` has not been invoked even if use `WithKernel()` when bind `FromSubContainerResolve()`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using Zenject; | |
public class SampleInstaller : MonoInstaller<SampleInstaller> | |
{ | |
public override void InstallBindings() | |
{ | |
Container | |
.Bind(typeof(IMain)) | |
.FromSubContainerResolve() | |
.ByMethod( | |
container => | |
{ | |
container.BindInterfacesTo<Main>().AsCached(); | |
container.BindInterfacesTo<Sub>().AsCached(); | |
} | |
) | |
.WithKernel() | |
.AsCached() | |
.NonLazy(); | |
} | |
private interface IMain | |
{ | |
} | |
private interface ISub | |
{ | |
void Test(); | |
} | |
private class Main : IMain | |
{ | |
public Main(ISub sub) | |
{ | |
Debug.Log("Main: new"); | |
sub.Test(); | |
} | |
} | |
private class Sub : IInitializable, ISub | |
{ | |
public void Initialize() | |
{ | |
Debug.Log("Sub: Initialize"); | |
} | |
public void Test() | |
{ | |
Debug.Log("Sub: Test"); | |
} | |
} | |
} |
Expected:
Main: new
Sub: Test
Sub: Initialize
I think IInitializable.Initialize()
be invoked after construct instance and resolve bindings.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output log: