Hello Tornadoers. Does anyone have an idea regardi...
# tornadofx
k
Hello Tornadoers. Does anyone have an idea regarding following in TornadoFX? If there are multiple instances of the same Fragment, but with different state and data, is it possible to have different instances of the Controller for each of those Fragments?
s
You could pass it in as a parameter. Or you could find the fragment in a new scope, passing in the instance of the controller into that scope. https://docs.tornadofx.io/0_subsection/3_components#passing-parameters-to-views
k
Yep, thanks. I was confused by the documentation as it said that Controller is always a singleton. But turns out I can also instantiate it multiple times directly (a bit hacky, but does the job though)
s
A Controller is always a singleton withing a Scope. Very important detail easy to miss. Where are you instantiating your controllers now then?
k
A Controller is always a singleton withing a Scope.
Yes, that's what I meant. So if I have multiple Fragments and for each I'm getting Controller from the Scope, it will always be the same Controller, which won't work properly as every Fragment must deal with own state and data. So what I'm doing (a bit hacky, but not critical for now) is that for each Fragment I instantiate a new Controller
at least I'm able to separate presentation layer from the business logic