hadashiA / VContainer

The extra fast, minimum code size, GC-free DI (Dependency Injection) library running on Unity Game Engine.
https://vcontainer.hadashikick.jp
MIT License
1.88k stars 163 forks source link

Fixed LifetimeScope's Container is null during build callback #586

Closed AlonTalmi closed 9 months ago

AlonTalmi commented 9 months ago

If you try and use the LifetimeScope's Container property during the container's build callback (for example when using the Instantiate extension method), the Container is null.

That happens because the Container property is assigned only after the Build method returns (which invokes the build callbacks).

As a quick fix I registered a build callback which registered the container to the Container property (before installing all other installers), that works because the build callback are called FIFO.

Edit: now also fixes AutoInjectGameobjects called after build callbacks which can easily cause duplicate injections if you instantiate an injected GameObject in a build callback

vercel[bot] commented 9 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vcontainer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 3, 2023 3:42pm