Here is what I'm doing:
I have a little GUI program (JavaFX) that contains a login and a main page. The main page is set up with a BorderPane
. The center of the BoraderPane is filled with different sub-scenes. This depends on which content the user wants to see.
Now, some sub-scenes execute tasks which require information about the user. Hence, I need to share my user among different controllers.
I did some research and I think I found a fitting solution: Create a User-Class which implements the singleton pattern.
This is where I get stuck. Since the user is unknown I can't create the User-Class in advance. First the user has to sign-up and then I can create the Singleton.
The referred link has a UserHolder
class which then holds a User
object.
Question:
1 Is it possible to create a Singleton that gets injected with information (parameters) before its instance is created?
2 If this is possible, how would this be done?