VContainer icon indicating copy to clipboard operation
VContainer copied to clipboard

Inject doesn`t work sometimes.

Open liderako opened this issue 9 months ago • 0 comments

I found some unclear issue with inject in vcontainer when sometimes inject is working and sometimes is not.

Come to Vcontainer after zenject and tried to make scene context, game object context, and project context. Added some code to project context to add via inspector different installers like in zenject. After that scene context inheritane project context, and game object context inheritane scene context.

public class ProjectContext : LifetimeScope
{
    public List<BaseInstaller> Installers;
    protected override void Configure(IContainerBuilder builder)
    {
        base.Configure(builder);
        foreach (var installer in Installers)
        {
            installer?.Install(builder);
        }
    }
}

public class SceneContext : ProjectContext {}

public class GameObjectContext : SceneContext 

In scene context at scene i choise parent as project context (before of couse add prebad project context like in documantation) Added few different installers for scene context, add few game object context with their own installers and link to scene context as parent via inspector.

So in this scenario sometimes inject is working and sometimes is not...

When i change code and delete my inheritance, and add this code to every class inject always is working.

  public List<BaseInstaller> Installers;
 protected override void Configure(IContainerBuilder builder)
 {
     base.Configure(builder);
     foreach (var installer in Installers)
     {
         installer?.Install(builder);
     }
 }

I understand problem in unclear searching parent or something like that, but i didn`t find about some sort of issues/warning in documantation, so i hope my experience with this issue will help to someone in future.

liderako avatar Mar 09 '25 19:03 liderako