Async Contaienr Build

VContainer executes pre-processing such as reflection when building a container. To reduce main thread blocking time for your game:

  1. Set false to LifetimeScope.autoRun
  2. After scene loading, Call LifetimeScope.Build manually.

For example:

var nextScene = await LoadSceneAsync(...);
var lifetimeScope = LifetimeScope.Find<MyLifetimeScope>(nextScene.Scene);
// Your async solution here.
await UniTask.Run(() => lifetimeScope.Build());

⚠️ Unity dependent features such as builder.RegisterComponentInHierarcky() do not work on background threads.

If this causes an error, use Awake instead.

For example:

class GameLifetimeScope : LifetimeScope
{
Ground groundInScene;
protected override void Awake()
{
// Run main thread.
groundInScene = FindObjectOfType<Ground>();
base.Awake();
}
protected override void Configure(IContainerBuilder builder)
{
// It can run background thread.
builder.RegisterInstance(groundInScene);
}
}