02. IInitializable<T…>

  05. Reference No Comments

Methods

void Init(TFirstArgument firstArgument, … TwelfthArgument twelfthArgument);

Classes that implement IInitializable<T…> have all the same functionality that they would get by implementing an IArgs<T…> interface, but with additional support for their Init function to be called manually by other classes.

This makes it possible for classes to inject dependencies even in cases where the object does not actively retrieve them during its initialization phase.

It also makes it possible to initialize the same object with dependencies more than once, which might be useful for example when utilizing an Object Pool to reuse your instances.

For MonoBehaviour derived classes it is generally recommended to implement IInitializable<T…> and not just IArgs<T…>. This is because the Awake event function does not get called for MonoBehaviour on inactive GameObjects, which means that dependency injection could fail unless the injector can manually pass the dependencies to it.

Leave a Reply

Your email address will not be published. Required fields are marked *