タグ

*guiceに関するyamadarのブックマーク (3)

  • GuiceでDI: BindingAnnotation

    先のGuiceでDI、のエントリ中で、NamedというAnnotaionを使った名称で実装を区別...の話を書いたが、Google Docで公開されている資料によるとGuiceではNamed Annotationは非推奨らすぃ。 文字列で名称を与えるのが気に喰わないらしい。まぁ確かにそうだ。せっかくJavaで全部やるんだから…というワケで、どのような方法が推奨されているかというと、名称を与えたBind専用のAnnotationを作る。先の例だと、「mysql」「postgresql」という文字列ではなく、いちいちその名称のAnnotationを作る。 "mysql"用のBindingAnnotationimport java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lan

    yamadar
    yamadar 2010/07/23
    bind(インタフェース).annotatedWith(アノテーションクラス).to(具象クラス);
  • Guiceを使ってみた - kenmazの日記

    今開発しているプログラムをGuiceを使って書いてみた。そもそもGuiceを使おうと決めた理由はテストを書き易くするため。実際に使ってみた感想としては「ま〜、こんなもんか」って感じ。 だいたいの使用パターンとしては以下のような感じになると思う。Guiceの高度な機能を使うと他の人がコードを読めなくなりそうなので最低限の機能だけ使うことにする。 まずはテスト時に差し替えたいクラスのIFを切り出しておく。 public interface LoginClient { public boolean login(String id, String password); } で、実コードを実装する。 public class LoginClientImpl implements LoginClient { public boolean login(String id, String password

    Guiceを使ってみた - kenmazの日記
    yamadar
    yamadar 2010/07/23
    何気に良記事
  • google-guice - Google Code

    Put simply, Guice alleviates the need for factories and the use of new in your Java code. Think of Guice's @Inject as the new new. You will still need to write factories in some cases, but your code will not depend directly on them. Your code will be easier to change, unit test and reuse in other contexts. Guice embraces Java's type safe nature. You might think of Guice as filling in missing featu

    google-guice - Google Code
  • 1