You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Container.Bind<Foo>().FromFactory<Foo.Factory>().AsSingle()
and Container.BindFactory<Foo, Foo.Factory>();
However, this results in
"Zenject.ZenjectException: Unable to resolve 'IProvider' while building object with type 'Foo.Factory'. Object graph:
Foo.Factory".
To Reproduce
public class Foo
{
public class Factory : PlaceholderFactory<Foo> {}
}
public class MyInstaller : Installer
{
Container.Bind<Foo>().FromFactory<Foo.Factory>().AsSingle();
Container.BindFactory<Foo, Foo.Factory>();
}
// container.Resolve<Foo>(); should work because zenject should be configured to create it by using the factory with a cached provider.
Expected behavior
I expect that Zenject would figure out which provider to use based on the AsCached or FromNew or something. Or I would expect the Finalizer to throw an exception during the binding step if I were doing something wrong (like an "error on previous binding" message). I think IProvider is internal to Zenject and I probably shouldn't try to fill this dependency myself.
Workaround
I can change Container.Bind<Foo>().FromFactory<Foo.Factory>()
to Container.Bind<Foo>().FromMethod((ctx) => ctx.Container.Resolve<Foo.Factory>().Create()
and it works as expected. I would think these would be functionally equivalent.
Am I doing something wrong to get this exception? Should I be doing the workaround instead of binding directly to a factory? The docs make it seem like this is the way to accomplish what I want.
Zenject version: 9
The text was updated successfully, but these errors were encountered:
Describe the bug
I'm trying to use the bindings:
Container.Bind<Foo>().FromFactory<Foo.Factory>().AsSingle()
and
Container.BindFactory<Foo, Foo.Factory>();
However, this results in
"Zenject.ZenjectException: Unable to resolve 'IProvider' while building object with type 'Foo.Factory'. Object graph:
Foo.Factory".
To Reproduce
Expected behavior
I expect that Zenject would figure out which provider to use based on the
AsCached
orFromNew
or something. Or I would expect the Finalizer to throw an exception during the binding step if I were doing something wrong (like an "error on previous binding" message). I think IProvider is internal to Zenject and I probably shouldn't try to fill this dependency myself.Workaround
I can change
Container.Bind<Foo>().FromFactory<Foo.Factory>()
to
Container.Bind<Foo>().FromMethod((ctx) => ctx.Container.Resolve<Foo.Factory>().Create()
and it works as expected. I would think these would be functionally equivalent.
Am I doing something wrong to get this exception? Should I be doing the workaround instead of binding directly to a factory? The docs make it seem like this is the way to accomplish what I want.
The text was updated successfully, but these errors were encountered: