- Home /
Zenject not resolving Queue Types
I am having a little trouble with Zenject resolving a Queue<T>
type and was wondering if anyone familiar with it could help me to understand if this is a limitation in Zenject or what may be wrong in the implementation below:
Here is my registration code:
Container.Bind<Queue<RenderTask>>().FromFactory<PipelineFactory>().AsSingle();
And here is my Factory:
public class PipelineFactory : IFactory<Queue<RenderTask>>
{
private readonly Scenario _scenario;
public PipelineFactory(Scenario scenario)
{
_scenario = scenario;
}
public Queue<RenderTask> Create()
{
return new Queue<RenderTask>(new List<RenderTask>
{
new DownloadTask(),
new LoadSceneTask(),
new LoadAssetsTask()
});
}
}
This creates this error:
ZenjectException: Unable to resolve 'Queue<RenderTask>' while building object with type 'PipelineService'. Object graph:
RenderManager
PipelineService
Better double check, but are you sure your call to Container.Bind
is called in your installer?
I've never faced any issue with any types with Zenject.
However, from what I see, do you need the factory?
Container.BindInstance(new Queue<RenderTask>(new List<RenderTask>
{
new DownloadTask(),
new LoadSceneTask(),
new LoadAssetsTask()
}));
I am indeed and yes I do unfortunately as I need to rely on injected services for the construction of the object and there is also configuration being injected into the factory.
I have had a look and apparently Ienumerables work and so would wrapping it in a class but for some reason other collection types are not supported. I havent dug into the code to see why that is, maybe they only support certain interfaces.
Answer by sacredgeometry · Jun 11, 2021 at 12:58 PM
After investigation this seems to be a problem with Zenject.
The solutions I found were to either use an IEnumerable instead or to wrap it in a wrapper class/ monad
Your answer
![](https://koobas.hobune.stream/wayback/20220613034854im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
iOS Dependency injection framework suggestions 4 Answers
Dependency injection related questions 0 Answers
Does Unity support application bootstrapping? 1 Answer
How do you generate a line between objects that are only instantiated upon game Start ? 1 Answer
Is there any Dependency Injection framework compatible with iOS? 1 Answer