Guice
Guiceã³ããã¿ã®Kevin Bourrillionæ°ã«ãã第2åãä»åã¯ä¸ç´ç·¨ã¨ããäºã§ãããå®è·µçãªå 容ã«ãªã£ã¦ãã¾ãã å ·ä½çã«ã¯InjectorãScopeã®ä½¿ãæ¹ãå¾®å¦ãªä»æ§ï¼ãã°ï¼ã«é¢ããçªã£è¾¼ãã 話ããã¹ãæ¹æ³ãä»å¾ã®ãã¼ã¸ã§ã³ã¢ããã«ã¤ãã¦ãªã©ã§ãã åç»ãâ¦
Guiceã³ããã¿ã§ããKevin Bourrillionæ°ã¨Bob Leeæ°ã«ãããã¬ã¼ã³åç»ã¨ãã®è³æãå ¬éããã¾ããã Java on Guice: Dependency Injection Java Way ãã¬ã¼ã³è³æ(PDF) âåç»ãè²¼ãä»ãã¦ã¿ã¾ããã http://video.google.com/videoplay?docid=606844741087â¦
1åç®ã«ç¶ããSpring Java Configurationã試ãã¦ã¿ããã¨æãã¾ããä»åã¯AOPãã¡ãªã¿ã«ä»å±ã®ããã¥ã¡ã³ãã«ã¯AOPã®èª¬æãç¡ãã£ãã®ã§ï¼ãããM1ãªãªã¼ã¹ï¼ããã¹ãã±ã¼ã¹ãåèã«è©¦ãã¦ã¿ã¾ãã Spring Java Configurationã§ã®AOPå®ç¾© injectããServiceâ¦
ä»ç¥ã£ãã®ã§ãããGuiceä½ã£ã¦ãBob Leeããã¯dynaopã®ä½è ã ã£ããã§ãããBitter EJBã®èè ã®ä¸äººã¨ããã®ã¯ç¥ã£ã¦ããã®ã§ããããã¡ãã¯ç¥ãã¾ããã§ãããæãå½æå¨ç±ãã¦ããä¼ç¤¾ã®åå¼·ä¼ã§Swingã®ãã¬ã¼ã ã¯ã¼ã¯ãä½ããã¨ãã¦ãã¦ï¼åå è æ°äººã®æ§â¦
SpringFramework 2.0.4ã§ãã¡ããã©ãã³ããã¼ã¯ã«é¢ä¿ããé¨åã®ããã©ã¼ãã³ã¹ãã¥ã¼ãã³ã°ãè¡ã£ãã¨ã®äºãªã®ã§ï¼è©³ããã¯æ¬¡ã®ã¨ã³ããªåç §ï¼ãå度ãã³ããã¼ã¯ãè¡ãã¾ãããSeasar2ãææ°çã«å ¥ãæ¿ããä¸ã§ãã»ããã¢ããå¦çã³ã¼ããä¸é¨å¤æ´ãã¦ãâ¦
å æ¥è¡ãããJapan Springframework User Groupã®åå¼·ä¼ã§Guiceã«ã¤ãã¦ã©ã¤ããã³ã°ãã¼ã¯ããè³æãå ¬éãã¾ããï¼ã¢ãããã¼ããããã¨ããããã¾ãï¼å²©æ°¸ããï¼ã ããã°ãèªã¾ãã¦ããæ¹ã«ã¯æ°ããæ å ±ã¯ç¡ãã¨æãã¾ããããããããã°ã©ããã çºè¡¨è³â¦
Guice㨠Springframeworkã®æ大ã®éãã¯DIãAOPã®è¨å®ãJavaã³ã¼ãã§æ¸ããXMLã§æ¸ããã§ãããå®ã¯(?)Springã§ãJava ã³ã¼ãã«ããè¨å®ã®è¨è¿°æ段ãç¨æããã¦ãã¾ã*1ãä»åã¯ãã®"Spring Java Configuration"ãç°¡åã«è¦ã¦ã¿ã¾ãããªããã¾ã ãã¤ã«ã¹ãã¼â¦
AOPç¨éã®73%ãå ãããã©ã³ã¶ã¯ã·ã§ã³ç®¡ç*1ããããåããã°ã¨ããããGuiceã使ã£ã¦ã¿ããã¨ãã人ãå¢ãããããããªãã®ã§ãã¡ãã£ã¨è©¦ãã¦ã¿ã¾ãã ãã©ã³ã¶ã¯ã·ã§ã³æ©è½ã¯ä»ã©ã¤ãã©ãªã使ã Guiceã¯ãã©ã³ã¶ã¯ã·ã§ã³ã«é¢ããæ©è½ãä¸åæã£ã¦ãã¾ãâ¦
Springã¨ã®çµ±åæ段2ã¤ç®ãSpringIntegration#fromSpringã¡ã½ããã«ã¤ãã¦ã§ãã fromSpring()ã¡ã½ããã®ã¤ã³ã¿ãã§ã¼ã¹ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ãã /** Creates a provider which looks up objects from Spring using the given name. */ public static <T> </t>â¦
Guiceã®éçºè MLã§ã¯æ´»çºãªããåããç¶ãã¦ãã¦ãã©ãã©ãæ°ããææ¡ãçã¾ãã¦ããããããªã·ã¼ãèªããã¦ããããã¦ãã¾ããæ¢ã«æ¬¡ã®ãã¼ã¸ã§ã³ï¼1.1ï¼ã®ã©ãã«ãããã®ã§ãæ°ã«ãªãæ¹ã¯ãã¡ããå®ç¾ãããã©ããã¯åããã¾ããããSeasar2ã®HOT deployã¨â¦
Springçµ±åã®2åç®ã®äºå®ã§ããããåæã¨ãã¦Providerãç解ãã¦ããã¨è¯ãããã ã£ãã®ã§ï¼ã¨ããããç解ãã¦ããªãã¨APIãããåãããªãã£ãã®ã§ï¼ãäºå®ãå¤æ´ãã¦Providerãè¦ã¦ã¿ã¾ãã Providerã¤ã³ã¿ãã§ã¼ã¹ã¯ãKeyã¯ã©ã¹ã¨å ±ã«Guiceã®DIã®æ ¸ã¨ãªâ¦
Guiceã¯Springã¨çµ±åããçºã®ã¯ã©ã¹ãç¨æãã¦ãã¾ãããã®åããã°ãSpringIntegrationãçµ±åã¨è¨ã£ã¦ãæ§ã ãªå½¢æ ãèããããã¨æãã¾ãããç¾æç¹ã§Guiceãç¨æãã¦ããã®ã¯ãSpringã®ã³ã³ããã§ç®¡çããã¦ããBeanãGuiceããåå¾/injectã§ããããã«ãâ¦
ä¸è¨ã®Wikiã«å ¬éãã¾ãããã½ã¼ã¹ã®ç´æ¥è²¼ãä»ãã¯æ¸ãæ¹ãåãããªãã£ãã®ã§ãæ·»ä»ãã¡ã¤ã«ã«ãªã£ã¦ãã¾ãã ä¿®æ£ã追å ããã©ãã·ã¥ã¢ãããªã©å¤§æè¿ã§ãã http://www.wikihouse.com/arumani/index.php?Guice%2C%20Sring%2C%20S2%20%A5%D1%A5%D5%A5%A9%â¦
ããã¤ãæ段ãããã¾ãã ã¢ããã¼ã·ã§ã³ãã®ãã®ã§åºå¥ã ex ) @JasracService / @ElicenseService ã¢ããã¼ã·ã§ã³ã§æå®ããæååã§åºå¥ã ex) @Named("JASRAC") / @Named("eLicense") 以ä¸ãããããè¦ã¦ãã¾ãã ã¢ããã¼ã·ã§ã³ãã®ãã®ã§åºå¥ ã©ã®å®â¦
ã¡ãã£ã¨æ°åãåºãäºã®è²¬ä»»ãæãã¦ã¾ãâ¦ã åç½®ãããã¦ä¸ããã ãã¼ã¹ã¨ãªã£ã¦ããGuiceä»å±ã®ã½ã¼ã¹ã®JavaDocã³ã¡ã³ãã«ã¯ã以ä¸ã®æã§å§ã¾ã£ã¦ãã¾ãã"A semi-useless microbenchmark." 誤解ãæãã¤ã¤è¨ãã°ããã®ãã¤ã¯ããã³ããã¼ã¯ã¯ã大è±100ç²â¦
id:koichikããã«ãS2ãæ¯è¼ã«è¿½å ãã¦ãã¨ããã³ã¡ã³ããé ããã®ã§ãè¨ãããéãã®æ¹æ³ã§è¿½å ãã¦è©¦ãã¾ãããSeasar2ã®ãã¹ãã³ã¼ãã¯ã¾!ããã®Seasar2ç¨ã³ã¼ãã«koichikããã®è¨è¿°ã追å ããã ãã®ãã®ã§ããSeasar2ã¯è§¦ã£ãäºããªãã®ã§ã·ã³ã°ã«ãã³ãâ¦
ãã¿ã¾ããã以åã®Springã¨Guiceã®AOPããã©ã¼ãã³ã¹æ¯è¼ã§ããããã¹ãã³ã¼ãã«ééããããã¾ãã¦ãæ¡ä»¶ãåãã«ãªã£ã¦ã¾ããã§ããã Guiceã¯æ¯åã¨ã³ãã³ã¹ããã¤ã³ã¹ã¿ã³ã¹ãä½ã£ã¦ããä¸æ¹ãSpringã¯1ã¤ã®Proxyã使ãåãã¦ããã¨ããâ¦ãæ°åãè¦ã¦ä½â¦
Injectorã¯ã¹ã¬ããã»ã¼ãã ããã§ããInjectorã¯ã¤ã³ã¿ãã§ã¼ã¹ã ãã表ç¾ãè¥å¹²ä¸æ£ç¢ºãªæ°ããããã©ã
ã¤ã³ã¿ãã§ã¼ã¹ã®å®è£ ã¯ã©ã¹ãæå®ããæ¹æ³ã¯ããã®2ã§æ¸ããbind(ã¤ã³ã¿ãã§ã¼ã¹).to(å®è£ ã¯ã©ã¹);ãåºæ¬ã§ãããããä»ã«ãããã¤ããã£ã¦ããã®ä¸ã§ãã¡ãã£ã¨æ¯è²ãéã@ImplementedByã¢ããã¼ã·ã§ã³ãç´¹ä»ãã¾ãã ããã¯ã¤ã³ã¿ãã§ã¼ã¹ã«ã¢ããã¼ã·ã§â¦
â»ä¸è¨ã¯ã³ã¼ããééã£ã¦ãã¦è¨æ£ããã®ã§ããã®8ããåç §ä¸ããã ãã®5ã§id:shot6ããã«ã³ã¡ã³ããé ããäºããããAOP使ç¨æã®ããã©ã¼ãã³ã¹ãæ¯è¼ãã¦ã¿ã¾ãã使ãã®ã¯ãGuiceä»å±ã®ããã©ã¼ãã³ã¹æ¯è¼ã³ã¼ãã«AOPè¨å®ã¨AOPãæãã ã¡ã½ããã®å¼ã³åºãâ¦
ä½ã¶æãåã«Guiceãè¦ãæAOPãè¦å½ãããªãã£ãã®ã§ãããããSpringã®ä»£æ¿ã¨ãã¦ã¯ä½¿ãããã¨æã£ã¦ããã®ã§ãããAOPã使ããããã«ãªã£ã¦ãã¾ããã¾ãã¯ãå½æè¦ã¤ããããªãã£ãç§ã«ãè¦ã¤ããããããã«ãªãã¾ããããã®1ã§æ¸ããããã«ãGuiceã®AOPâ¦
Guiceã®ãã¹ãã³ã¼ãã«å«ã¾ãããããã©ã¼ãã³ã¹æ¯è¼æ¸¬å®ãå®è¡ãã¦ã¿ã¾ãã å 容ã¯ã以ä¸ã®ãããªä¾åé¢ä¿ãæããããªãã¸ã§ã¯ããã²ãããã³ã³ããããåå¾ãç¶ãã¦ã1ç§éã«åå¾ã§ããåæ°ã表示ããã¨ãããã®ã§ãã Foo foo = new Foo(); foo.setI(5);â¦
ãã®2ã§æ¸ããã³ã¼ãã§ã¯ãä¸è¨ã®ããã«ãã£ã¼ã«ãã«@Injectã宣è¨ãã¦Injectãã¦ã¾ããã @Inject private Service service; Guiceã¯ãã¡ããã¡ã½ãããã³ã³ã¹ãã©ã¯ã¿ã«ãInjectåºæ¥ã¾ãã import sample.guice.service.Service; import com.google.injectâ¦
ä¸çªåç´ãªãµã³ãã«ããã¦ã¼ã¶ã¬ã¤ãããå°ãå¤ãã¦æ¸ãã¦ã¿ã¾ãããããã®ããã¥ã¡ã³ãGoogle Docsã ã æ§æã¯ä»¥ä¸ã Service Injectããã¤ã³ã¿ãã§ã¼ã¹ ServiceImpl Injectããã¤ã³ã¿ãã§ã¼ã¹ã®å®è£ ã¯ã©ã¹ Client ServiceãInjectãããã¯ã©ã¹ Main èµ·åã¯â¦
以åååã®Måããåå¨ãæãã¦ããã£ãGoogleã®DIã³ã³ããGuiceã§ããããã§ãã1.0ã«ãªã£ããããªã®ã§ã¡ãã£ã¨è¦ã¦ã¾ããã ä¸è¨ã§è¨ãã¨ããã¢ããã¼ã·ã§ã³ã¨ã¸ã§ããªã¯ã¹ã使ããããã©ã¼ãã³ã¹ãéè¦ããDIã«ç¹åããDIã³ã³ãããã®ããã§ããã¨ãããâ¦