Skip to content

MemoryPool<Param, Value> with CustomFactory #286

@vodoleystudio

Description

@vodoleystudio

Describe the bug
I try to create a pool that gets param and value because I need this param in my custom factory for the correct initializing of instantiated objects.

The version without the param works as expected - (I mean MemoryPool, and related to it factories)

Unfortunately, the version with param cause to the exception that not clear to me why it's trying to resolve IFactory instead of the requested one - IFactory<IAtata, IKokoko>

When :
Container.Instantiate<MemoryPool<IAtata, IKokoko>>(new object[] { settings, factory });
the line is running, I get an error :
ZenjectException: Unable to resolve 'IFactory' while building object with type 'MemoryPool<IAtata, IKokoko>'. Object graph: MemoryPool<IAtata, IKokoko>

To Reproduce
Run an attached code in editor.

Expected behavior
That it will inject all as expected.

Screenshots
image

Extenject and Unity info (please complete the following information):

  • Zenject version: 9.2.0
  • Unity version: 2022.2.14
  • Project's scripting backend [e.g. Mono/IL2CPP] : IL2CPP

Additional context

public interface IAtata
{
    string Name { get; set; }
}

public interface IKokoko
{
    string Name { get; set; }
}

public class Kokoko : IKokoko
{
    public string Name { get; set; }

    public class Factory : PlaceholderFactory<IAtata, IKokoko>
    {
    }
}

public class KokokoFactory : IFactory<IAtata, IKokoko>
{
    public IKokoko Create(IAtata atata)
    {
        IKokoko kokoko = new Kokoko();
        kokoko.Name = atata.Name;
        return kokoko;
    }
}

public class Installer : MonoInstaller<Installer>
{
    public override void InstallBindings()
    {
        var settings = new MemoryPoolSettings()
        {
            InitialSize = 100,
            ExpandMethod = PoolExpandMethods.Double,
        };

        Container.BindFactory<IAtata, IKokoko, Kokoko.Factory>().FromFactory<KokokoFactory>().NonLazy();

        var factory = Container.Resolve<Kokoko.Factory>();

        // ZenjectException: Unable to resolve 'IFactory<IKokoko>' while building object with type 'MemoryPool<IAtata, IKokoko>'. Object graph: MemoryPool<IAtata, IKokoko>
        var pool = Container.Instantiate<MemoryPool<IAtata, IKokoko>>(new object[] { settings, factory });
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions