NonLazy doesn't seem to work with non generic types
Opened this issue · 3 comments
// Unfortunately FromResolveGetter does not have an untyped version so have to use FromMethod and a resolve world
container.Bind(type)
.FromMethodUntyped(i =>
{
Debug.Log("Executed"); // <-- we never get here
var world = i.Container.Resolve<World>();
var system = (ScriptBehaviourManager)container.Instantiate(type);
world.AddManager(system);
return system;
})
.AsSingle().NonLazy();
Alternative
container.Bind(type)
.FromNew()
.AsSingle()
.OnInstantiated((i, o) =>
{
var world = i.Container.Resolve<World>();
world.AddManager((ScriptBehaviourManager)o);
})
.NonLazy();
Neither of these work unless I explicitly gather all the types and resolve them manually
private class InitializeWorlds
{
public InitializeWorlds (List<Type> types, DiContainer container)
{
foreach (var type in types)
{
container.Resolve(type);
}
}
Side note, I was using FromResolveGetter for a generic version of this but i wanted a non generic alternative to automatically bind all systems in project but there is no FromResolveGetterUnTyped unfortunately.
Hmm. It totally works in my standalone test project though.
public override void InstallBindings()
{
Container.Bind(typeof(TestClass)).FromMethod(_ =>
{
Debug.Log("TestClass");
return new TestClass();
}).AsSingle().NonLazy();
}
private class TestClass
{
}
Now I'm really confused what is going on
Ok, after realizing my standalone case works I went back and had a look.
It was basically an infinite loop that Zenject stopped (but didn't warn me.)
Basically World was created in a FromMethod and within that FromMethod is where all the system bindings resided.
So yeah, please close, not an issue.
But side note, FromResolveGetterUnTyped would be great!
Glad you got it working. I'll re-open this so I remember to add FromResolveGetterUnTyped and also look at why you didn't get a proper error message here