Guice injection in a jenkins plugin?

我的未来我决定 提交于 2020-01-01 10:14:56

问题


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.createInjector() 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.

来源:https://stackoverflow.com/questions/27849291/guice-injection-in-a-jenkins-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!