tarject
  • Documentation
    • Introduction
    • Installation
    • How to Contribute
    • How to Use
      • Context
        • ProjectContext
        • SceneContext
        • GameObjectContext
      • Installer
        • GameObjectInstaller
        • ObjectInstaller
      • Binding Methods
        • Bind
        • BindFromInstance
        • BindFromHierarchy
        • BindFactory
      • Binding Options
        • ToInterface
        • WithId
        • Lazy
      • Injecter
      • Factory
        • SeparatedGameObjectFactory
        • SeparatedObjectFactory
      • Interfaces
      • Signal Management
      • Test Framework
Powered by GitBook
On this page
  1. Documentation
  2. How to Use
  3. Binding Options

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
}
PreviousWithIdNextInjecter

Last updated 6 months ago