Created
September 16, 2013 13:42
-
-
Save qrtt1/6580834 to your computer and use it in GitHub Desktop.
沒想到,竟然有用 hk2 做 dependency injection 的一天。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.web.toolkits; | |
import javax.inject.Singleton; | |
import my.web.toolkits.ydl.YoutubeSignature; | |
import org.apache.commons.logging.Log; | |
import org.apache.commons.logging.LogFactory; | |
import org.glassfish.hk2.api.Factory; | |
import org.glassfish.hk2.utilities.binding.AbstractBinder; | |
import org.glassfish.jersey.server.ResourceConfig; | |
public class MyApplication extends ResourceConfig { | |
static Log logger = LogFactory.getLog(MyApplication.class); | |
public MyApplication() { | |
register(new MyApplicationBinder()); | |
} | |
static class MyApplicationBinder extends AbstractBinder { | |
@Override | |
protected void configure() { | |
bindFactory(new Factory<YoutubeSignature>() { | |
@Override | |
public YoutubeSignature provide() { | |
YoutubeSignature signature = new YoutubeSignature(YoutubeSignature.SCRIPT_URL); | |
signature.addReportReceiver("[email protected]"); | |
return signature; | |
} | |
@Override | |
public void dispose(YoutubeSignature instance) { | |
} | |
}).to(YoutubeSignature.class).in(Singleton.class); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment