Just played a bit with it in my plugins (and I guess I'm gonna use more DI
from now on), IIUC your example, you indeed should mark the related classes
with @Extension so that the "system" knows about them.

So, in your example, I think you should just NOT have a class like
your MyGuiceModule.java because Jenkins is gonna auto-discover classes
marked @Extension, and then add @Extension on MySvcImpl and MyPublisher.
And be done.

Worked for me.

HTH

2014-12-18 1:08 GMT+01:00 Dan Alvizu <dalv...@pingidentity.com>:

> Hi,
>
> I just wrote this wiki page on how to do dependency injection in a plugin:
>
> https://wiki.jenkins-ci.org/display/JENKINS/Dependency+Injection
>
> I want to use this so that I can provide a move requests to external
> resource to a service class and pass a mock to my Publisher during unit
> tests.
>
> The problem with the example I gave in the wiki is that I cannot provide a
> mock easily:
>
>     @Override
>     public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, 
> BuildListener listener)
>     {
>         Guice.createInjector(new MyModule()).injectMembers(this);
>         // ...        mySvc.myServiceMethod(); // "it works!"    }
>
>
> I need to remove that Guice.creatInjector() line.
>
> Is it possible to mark the AbstractModule subclass to be 'picked up' by
> Guice? I tried marking it with @Exension from comments here
> https://issues.jenkins-ci.org/browse/JENKINS-8751 but it's not being
> injected.
>
>
>  --
> 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-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-dev/fdcc62d6-c347-4239-97cc-26560b4014ba%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-dev/fdcc62d6-c347-4239-97cc-26560b4014ba%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



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

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/CANWgJS4hxi48cT%2BqB-23bEjNdC5ZaFK5HRP4ew_%2BsGn%3Dj%3D_DGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to