Lazy

Objects are created from lazy binded classes only when needed. If the class is not Lazy Bind, an object from that class is created in the relevant Context's Awake, but if Lazy Bind is made, the object is created only when there is a place to be injected.

Sample uses:

public class AppInstaller : GameObjectInstaller
{
    public override void Install(DIContainer container)
    {
        container.Bind<InventoryData>().Lazy();
    }
}
public class FooMono : MonoBehaviour
{
    [Inject]
    private readonly InventoryData _inventoryData;
    //InventoryData is created and injected when FooMono is instantiated
}

Last updated