Dependency Incjection in Godot possible?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Oian

Hi,

is it possible to use Dependency Injection in Godot (GDscript)? Maybe its already implemented in some way and im just not seeing it.

Should you even bother using DI or are there better ways to decouple things in Godot (apart from signals) ?

Im not having a specific problem, just curious if DI is good practice in Godot (if you can even use it).

Thanks.

:bust_in_silhouette: Reply From: kbal

Give your class an init-function with the DI-object as parameter and call it after you create the class instance with .new(). Basically like a constructor in other languages.