I'm asking myself for a while how to do CDI in Netbeans Platform especially with TopComponents or subclasses of them. Now i'm using LookUps to get my dependencies and for inter-module-communication and it's working fine, but the dependencies of my components are not visible to the outside like it is using CDI so I'm searching for a way to populate the constructors of my TopComponents with the right arguments (Loose-Coupled trough interface types). I currently using 3 modules:
As you see both Modules (GUI and Core) rely on API because of the loose-coupling in the modular system. I think it is nice to use LookUps to find the right implementations for the interfaces in API but as I said I also want to have the dependencies visible to the outside of my component classes.
So is there any way for doing Constructor Dependency Injection in a modular loose-coupled architecture using Netbeans Platform(Version 8.0.2) and if yes how?
If no what is the best solution to provide a clear view on the dependencies of the component classes?
Any help will be appreciated.
I think I found a solution that solves part of the problem. Normally my TopComponents are getting accessed trough
Window -> TopComponentNameHere
action (Which is generated by the Annotations I use for the TopComponent?).
The thought was that you can also initialize the TopComponent inside of Actions and show them too. Here you use a simple new Statement to create an Object of the TopComponent you want to show. Here is the point: You can load the components dependencies before via LookUps and pass them directly into the constructor (In my eyes not a full solution because the action has to initialize the TopComponent, but however).
I think this is way more beautiful than grabbing the dependencies right in the Component initialization Code and is enough for the moment for me to live with.