How to have one instance of a class shared by an action and a tool window?
Answered
I have a tool window and I have an action. I also have some class (let's call it class X). I would like the tool window class and action class to use class X. But I would like them to use the same instance of class X. So the instance of the class X should be created at the beginning (when the plugin starts) and then the tool window class and the action class should be able to access the instance of class X created at the beginning. How to accomplish that?
I think I could use Singleton pattern for that. Is there a better approach?
Please sign in to leave a comment.
Use services, which also allow lifecycle control and per-project scope amongst others. https://plugins.jetbrains.com/docs/intellij/plugin-services.html