seesharper/LightInject

Integration with Godot Engine

ksvslk opened this issue · 7 comments

Would it be possible to use this with Godot Engine. I've tried to inject properties but they will not resolve. Injection to constructor is not possible because Godot objects extend Node which need a parameterless constructor. Is there any way to use DI in this engine or LightInject would need another integration?

I have no idea😊. Do they have a story for dependency injection at all? In order for LightInject to inject property dependencies, the object containing those properties must be resolved through the container

I have no idea😊. Do they have a story for dependency injection at all? In order for LightInject to inject property dependencies, the object containing those properties must be resolved through the container

There are some methods to achieve IoC - but these are not pretty or very useful for me.

https://docs.godotengine.org/en/stable/getting_started/workflow/best_practices/scene_organization.html#how-to-build-relationships-effectively

That documentation did not exactly explain how to do DI in detail 😊. I just took a brief look at this and it seems like the Node class is essential here. Maybe there is somewhere you can define a Func for creating nodes? Btw found this https://github.com/firebelley/GodotTutorials/tree/master/csharp/003_dependency_injection maybe that can help?

I will look at the examples and think about it. Yeah, the Node class is the main character :)
I think I have seen that DI example but I'm not sure if this is real DI - probably not:
https://github.com/firebelley/GodotTutorials/blob/master/csharp/003_dependency_injection/scripts/Player.cs
As it is doing new in the _Ready function. But the whole point should be to avoid such coupling?
But thanks for replying!

It is what usually is referred to as "Method Injection" which is not very common in DI. Also found this issue which might indicate that they still have some work to be done in order to be DI friendly, 😊 godotengine/godot-proposals#376

Yes, It seems to be hard to do "classical" constructor injection in Godot so I'm thinking it is not worthwhile. Maybe I can do it in some other way.

I'm closing since it is not really related to LightInject.