SlideShare a Scribd company logo
1 of 14
JSUG 第 2 回ライトニングトーク Google Guice モンスター・ラボ 稲村創( so.inamura@monstar-lab.com) 音楽配信サイト: http://monstar.fm ブログ: http:// d.hatena.ne.jp/arumani /
Guice とは ,[object Object],[object Object],[object Object],[object Object]
Guice の特徴 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3ステップ DIサンプル ,[object Object],public class Client { @Inject private Service service; @Inject public Client(Service service) { this.service = service; } @Inject public void injectMethod(Service service) { this.service = service; }  }
3ステップ DIサンプル ,[object Object],public class MyModule extends AbstractModule { protected void configure() { // Service という型があったら、 ServiceImpl クラスを inject する bind( Service.class ).to( ServiceImpl.class ); } }
3ステップ DIサンプル ,[object Object],public static void main(String[] args) { Injector injector = Guice.createInjector(new MyModule()); Client client =   injector.getInstance(Client.class); client.execute(); }   ⇒ DI 済インスタンス取得!
3ステップ AOPサンプル ,[object Object],// AOP Alliance のインタフェースを使ったインターセプタを実装 public class LoggingInterceptor  implements MethodInterceptor  { public Object invoke(MethodInvocation methodInvocation) throws Throwable { System.out.println("AOP から出力 "); //  本来の処理を実行 return methodInvocation.proceed(); } }
3ステップ AOPサンプル ,[object Object],protected void configure() { bind(Service.class).to(ServiceImpl.class); bindInterceptor( //  対象クラス(この例はパッケージ一括指定) inPackage(Service.class.getPackage()) //  対象メソッド(この例は全メソッド指定) , any() //  インターセプタ , new LoggingInterceptor()); }
3ステップ AOPサンプル ,[object Object],public static void main(String[] args) { Injector injector = Guice.createInjector(new MyModule()); Client client =  injector.getInstance(Client.class); client.execute(); }   ⇒ weave 済インスタンス取得!
Spring連携サンプル // Spring コンテナ作成 ApplicationContext context =  new ClassPathXmlApplicationContext(&quot;context.xml&quot;); Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(BeanFactory.class).toInstance(context);  // context.xml に //  <bean id= “ foo ”  class=“ FooImpl ” /> //  と書いてあるとして bind( Foo.class ).toProvider(fromSpring( Foo.class,  “foo&quot; ) ); } });
FAQ ,[object Object],[object Object],[object Object],[object Object]
FAQ ,[object Object],[object Object],[object Object]
リンク ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]

More Related Content

Viewers also liked

NRKbeta - Webdagene 2008
NRKbeta - Webdagene 2008NRKbeta - Webdagene 2008
NRKbeta - Webdagene 2008Oyvind Solstad
 
シックス・アパート・フレームワーク
シックス・アパート・フレームワークシックス・アパート・フレームワーク
シックス・アパート・フレームワークTakatsugu Shigeta
 
I Want More Traffic Now!
I Want More Traffic Now!I Want More Traffic Now!
I Want More Traffic Now!Karim Gargum
 
Lug Roma3 Corso Linux Base
Lug Roma3   Corso Linux BaseLug Roma3   Corso Linux Base
Lug Roma3 Corso Linux Basefosk
 
Portfolio interoperability progress in the UK
Portfolio interoperability progress in the UKPortfolio interoperability progress in the UK
Portfolio interoperability progress in the UKSimon Grant
 
Deprivileging The Digital
Deprivileging The DigitalDeprivileging The Digital
Deprivileging The DigitalTony McNeill
 
Polygons
PolygonsPolygons
Polygonspotc
 
Mashups - webforum 2009 (Øyvind Solstad)
Mashups - webforum 2009 (Øyvind Solstad)Mashups - webforum 2009 (Øyvind Solstad)
Mashups - webforum 2009 (Øyvind Solstad)Oyvind Solstad
 
Platfrom for community-based solutions
Platfrom for community-based solutionsPlatfrom for community-based solutions
Platfrom for community-based solutionsLatte Media
 
Durmak Yok Yolsuzluga Devam
Durmak Yok Yolsuzluga DevamDurmak Yok Yolsuzluga Devam
Durmak Yok Yolsuzluga Devammillitrk
 

Viewers also liked (20)

NRKbeta - Webdagene 2008
NRKbeta - Webdagene 2008NRKbeta - Webdagene 2008
NRKbeta - Webdagene 2008
 
シックス・アパート・フレームワーク
シックス・アパート・フレームワークシックス・アパート・フレームワーク
シックス・アパート・フレームワーク
 
I Want More Traffic Now!
I Want More Traffic Now!I Want More Traffic Now!
I Want More Traffic Now!
 
Lug Roma3 Corso Linux Base
Lug Roma3   Corso Linux BaseLug Roma3   Corso Linux Base
Lug Roma3 Corso Linux Base
 
Portfolio interoperability progress in the UK
Portfolio interoperability progress in the UKPortfolio interoperability progress in the UK
Portfolio interoperability progress in the UK
 
Deprivileging The Digital
Deprivileging The DigitalDeprivileging The Digital
Deprivileging The Digital
 
Quote Presentation2
Quote Presentation2Quote Presentation2
Quote Presentation2
 
building BRIDGES
building BRIDGESbuilding BRIDGES
building BRIDGES
 
Future Shapers.Ppt
Future Shapers.PptFuture Shapers.Ppt
Future Shapers.Ppt
 
PR30
PR30PR30
PR30
 
Guimãraes (Portugal)
Guimãraes (Portugal)Guimãraes (Portugal)
Guimãraes (Portugal)
 
Polygons
PolygonsPolygons
Polygons
 
Mashups - webforum 2009 (Øyvind Solstad)
Mashups - webforum 2009 (Øyvind Solstad)Mashups - webforum 2009 (Øyvind Solstad)
Mashups - webforum 2009 (Øyvind Solstad)
 
Ma ed 2014
Ma ed 2014Ma ed 2014
Ma ed 2014
 
A/B Testing 101
A/B Testing 101A/B Testing 101
A/B Testing 101
 
Platfrom for community-based solutions
Platfrom for community-based solutionsPlatfrom for community-based solutions
Platfrom for community-based solutions
 
Oporto
OportoOporto
Oporto
 
No phai tra 4
No phai tra   4No phai tra   4
No phai tra 4
 
Durmak Yok Yolsuzluga Devam
Durmak Yok Yolsuzluga DevamDurmak Yok Yolsuzluga Devam
Durmak Yok Yolsuzluga Devam
 
NCE Tourism Bergen
NCE Tourism BergenNCE Tourism Bergen
NCE Tourism Bergen
 

Recently uploaded

新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NTT DATA Technology & Innovation
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video UnderstandingToru Tamaki
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Hiroshi Tomioka
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Gamesatsushi061452
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...Toru Tamaki
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルCRI Japan, Inc.
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイスCRI Japan, Inc.
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)Hiroshi Tomioka
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 

Recently uploaded (11)

新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 

Google Guice - JSUG第2回勉強会ライトニングトーク

  • 1. JSUG 第 2 回ライトニングトーク Google Guice モンスター・ラボ 稲村創( so.inamura@monstar-lab.com) 音楽配信サイト: http://monstar.fm ブログ: http:// d.hatena.ne.jp/arumani /
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Spring連携サンプル // Spring コンテナ作成 ApplicationContext context = new ClassPathXmlApplicationContext(&quot;context.xml&quot;); Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(BeanFactory.class).toInstance(context); // context.xml に // <bean id= “ foo ” class=“ FooImpl ” /> // と書いてあるとして bind( Foo.class ).toProvider(fromSpring( Foo.class, “foo&quot; ) ); } });
  • 11.
  • 12.
  • 13.
  • 14.