-
Notifications
You must be signed in to change notification settings - Fork 272
Support for creating components using constructor via dependency injection #1264
base: master
Are you sure you want to change the base?
Conversation
Your option gives priority to non-native DI. It also becomes unclear where we got the instance from (from which DI). |
dicontainer property of the FX class in which the changes take place. |
for other DIs you need to use:
What are the reasons for TornadofX DI behavior change? |
My idea is to make it possible to use di through the constructor, ideally it should be for the native di too. |
Yes, but this requires some serious work on the concept rather than changing a few lines (maybe it should be done in Tornadofx 2.0). Where is your constructor with parameters here? You just get an instance from your DI scope, nothing has changed on the Tornadofx side. Also, will your DI take into account the differences between |
Lunch is over, I'll write it in the evening |
If we do a major rewrite of the dependency injection mechanism in TornadoFX, I suggest making third party injection frameworks a first class citizen perhaps? TornadoFX could ship with a simple mechanism like it has now, with the ability to plug in a third party extension for all the roles the native mechanism is used for. |
Well, there is one option for automatic inject through the constructor (through the same reflection). And it shouldn't break old code. The logic is simple, we check the parameters of the primary constructor and look for the necessary dependencies in the scope. The problem can only cause recursive component dependencies Today or tomorrow I will try to provide the code. EDIT: To integrate with other DI, need to think about how to design it better and work out the details |
a big drawback of the approach - parameters with types that cannot be injected can be passed to the constructor simple sample:
|
Details here
Sorry about my english