Dependency Injection / Sezpoz / Guice scanning

43 views
Skip to first unread message

Baptiste Mathus

unread,
Oct 13, 2015, 7:57:24 AM10/13/15
to jenkin...@googlegroups.com
Hi,

Just tried to use DI in Jenkins in a particular case that didn't work. Just wanted to check if this was supposed to be a supported use case and get feedback.

It's a multimodules project:

* xyz-jenkins-plugin
* library

xyz-jenkins-plugin depends on library.

In library there're two classes:
* SomeFacade (interface)
* SomeFacadeImpl (impl class, annotated @Extension)

In xyz-jenkins-plugin in a Jenkins/Sezpoz managed class, I put 

public class ... {
   @Inject
   SomeFacade someFacade;
}

But this crashes when Jenkins starts:

1) No implementation for ...SomeFacade was bound.
  while locating ..SomeFacade
    for field at ...SomeUI.someFacade(Unknown Source)

Is this expected? Maybe the scanning doesn't include dependent jars?

Thanks

--
Baptiste

Jesse Glick

unread,
Oct 13, 2015, 12:43:27 PM10/13/15
to Jenkins Dev
On Tue, Oct 13, 2015 at 7:57 AM, Baptiste Mathus <bma...@batmat.net> wrote:
> In xyz-jenkins-plugin in a Jenkins/Sezpoz managed class, I put
>
> public class ... {
> @Inject
> SomeFacade someFacade;
> }

Only works if the referring class is itself an `@Extension`. Otherwise
who is going to know it needs stuff injected?

Oleg Nenashev

unread,
Oct 13, 2015, 3:22:09 PM10/13/15
to Jenkins Developers
Probably you also need a Guice Module definition to perform binding.

вторник, 13 октября 2015 г., 19:43:27 UTC+3 пользователь Jesse Glick написал:

Baptiste Mathus

unread,
Oct 13, 2015, 3:41:59 PM10/13/15
to jenkin...@googlegroups.com
Yeah, neither do I believe in magic :). Actually this is the case, I forgot to put it.

And actually, this is a wee bit more complicated.

The @Extension is on a class which extends an abstract class which is the one having the @Inject.

I guess I'm gonna try and put some simple example on GitHub to clarify.


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr3n7RuWU6NPY_K%3DqLEkF7L_gU5Yc4ZpJ-3njk4NWJgiPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !

Baptiste Mathus

unread,
Oct 13, 2015, 3:45:36 PM10/13/15
to jenkin...@googlegroups.com
Good question. I'm not really Guice-savvy, but I thought that was not required. 
Indeed, since both components are @Extension annotated, hence known by Sezpoz, everything required should be known by the injection engine? 
I don't see why having more code would be necessary?

Cheers

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Jesse Glick

unread,
Oct 13, 2015, 5:53:43 PM10/13/15
to Jenkins Dev
On Tue, Oct 13, 2015 at 3:41 PM, Baptiste Mathus <bma...@batmat.net> wrote:
> The @Extension is on a class which extends an abstract class which is the
> one having the @Inject.

Well, maybe it will work, but probably not.

Are you really getting any value from the half-baked DI system in
Jenkins? Seems a lot easier to just give up and use
`ExtensionList.lookup`.
Reply all
Reply to author
Forward
0 new messages