タグ

ブックマーク / shin1o.blogspot.com (1)

  • 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(具象クラス);
  • 1