how to inject active project reference to a project service (for initialization)

is there a way to 'inject' active project reference to a project service ?
For example as a constructor parameter - as in project components ?
I tried using this approach (defined a service constructor with a single Project-type parameter) but the default no-parameter constructor seems to have been used instead.
I also tried browsing IDEA API for 'ProjectService' interfaces that could provide such functionality (when implemented by the service class) but haven't found anything suspicious.
The only workaround I came up with is this :

        StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new Runnable() {
            public void run() {
                CompletionTargetService completionTargetService = ServiceManager.getService(myProject, CompletionTargetService.class);

I explicitly initialize my service in projectOpened() method of my project component and pass it the reference i need - but it feels like an ugly hack and I'd be grateful for a hint on how to do it properly.
THX in advance,

[UPDATE] I could also use a simple project component but I guess it would be just another workaround.

Comment actions Permalink

How is your service registered in plugin.xml? If it's a project service, constructor injection for Project just works, there is no need for any interfaces or workarounds.

Comment actions Permalink

you're right, it works just fine.
I must have messed something up - sorry about that (I'm such a noob:/)
Thank you for your patience, I will test my future enquiries more thoroughly before posting here.


Please sign in to leave a comment.