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. Factory

SeparatedGameObjectFactory

It is used to instantiate objects derived from MonoBehaviour. When inheriting this class, the objects and parameters to be created must be defined as types.

Sample uses:

public class Installer : GameObjectInstaller
{
    public override void Install(DIContainer container)
    {
        container.BindFactory<FooItem.Factory>();
    }
}

public class SampleClass : MonoInjecter
{
    [Inject]
    private readonly FooItem.Factory _fooItemFactory;

    [SerializeField]
    private FooItem _fooItemPrefab;

    protected override void Awake()
    {
       base.Awake();

        FooItem fooItem = _fooItemFactory.Create(_fooItemPrefab, "Sample string");
    }
}

public class FooItem : MonoBehaviour,  IFactorable<string>
{
    [Inject]
    private readonly Foo _foo;

    public void InitializeFactory(string variable)
    {
        Debug.Log($"{_foo.index}: String variable is: {variable}");
    }

    public class Factory : SeparatedGameObjectFactory<FooItem, string>  { }
}
PreviousFactoryNextSeparatedObjectFactory

Last updated 6 months ago