2007-03-01から1ヶ月間の記事一覧
サンプル:JNDIを使った統合Say for example we want to bind to objects from JNDI. We could implement a reusable custom provider similar to the one below. Notice we inject the JNDI Context:たとえばJNDIに登録されたオブジェクトをバインドしたい…
バインディングの範囲付けBy default, Guice creates a new object for every injection. We refer to this as having "no scope." You can specify a scope when you configure a binding. For example, to inject the same instance every time:デフォルト…
スコープアノテーションの作り方Annotations used for scoping should:範囲指定のために使うアノテーションは以下のように作成します。 Have a @Rentention(RUNTIME) annotation so we can see the annotation at runtime. Have a @Target({TYPE}) annotatio…
熱心なバインディングのロードGuice can wait to load singleton objects until you actually need them. This helps speed up development because your application starts faster and you only initialize what you need. However, sometimes you always …
スコープをまたいでインジェクトする場合You can safely inject objects from a larger scope into an object from a smaller scope. For example, you can inject an Http session-scoped object into an HTTP request-scoped object. However, injecting i…
デベロップメントステージ(開発・テスト環境ステージ)Guice is aware that your application goes through different stages of development. You can tell it which stage the application is running in when you create a container. Guice currently s…
メソッドのインターセプトGuice supports simple method interception using the AOP Alliance API. You can bind interceptors from your modules using Binder. For example, to apply a transaction interceptor to methods annotated with @Transactiona…
スタティックStatic変数・メソッドへのインジェクションStatic fields and methods make testing and reusing more difficult, but there are times where your only choice is to keep a static reference to the Injector. スタティックフィールドとメソッ…
省略可能なインジェクションSometimes your code should work whether a binding exists or not. In these cases, you can use @Inject(optional=true) and Guice can override your default implementation with a bound implementation when available. For…
文字列へのバインドWe try to avoid using strings whenever possible as they're prone to misspellings, not tool friendly, and so on, but using strings instead of creating custom annotations can prove useful for quick and dirty code. For these…
Struts 2 サポートTo install the Guice Struts 2 plugin with Struts 2.0.6 or later, simply include guice-struts2-plugin-1.0.jar in your web application's classpath and select Guice as your ObjectFactory implementation in your struts.xml file…
カウントするサンプルSay for example that we want to count the number of requests in a session. Define a Counter object which will live on the session:例として、セッション中のリクエストの数を数える機能を持ったサンプルを挙げましょう。Session…
JMXへのインジェクションSee com.google.inject.tools.jmx.APIの「com.google.inject.tools.jmx」を参照してください。
注釈によるバインディングIf you need multiple bindings to the same type, you can differentiate the bindings with annotations. For example, to bind an interface Service and annotation @Blue to the concrete implementation BlueService, call:複…
DRY (自分で書いたものを繰り返すな!)Repeating "binder" over and over for each binding can get a little tedious. Guice provides a Module support class named AbstractModule which implicitly gives you access to Binder's methods. For example…
依存性のバインディングHow does Guice know what to inject? For starters, a Key composed of a type and an optional annotation uniquely identifies a dependency. Guice refers to the mapping between a key and an implementation as a Binding. An …
独力で動くアプリケーションThe idea of bootstrapping is fundamental to dependency injection. Always explicitly asking the Injector for dependencies would be using Guice as a service locator, not a dependency injection framework.「独力で動く…
属性つきのアノテーションIf you can get by with marker annotations alone, feel free to skip to the next section.もし、あなたがマーカーアノテーションだけでやっていくことができるなら、遠慮なく次のセクションまでスキップしてください。You can al…
バインディング用のアノテーションを作るWhere did this @Blue annotation just mentioned come from? You can create such an annotation easily, although the standard incantation you have to use is unfortunately a little complex:先ほど話題に出た…
導入The enterprise Java community exerts a lot of effort toward wiring objects together. How does your web application get access to a middle tier service, or your service to the logged in user or transaction manager? You'll find many gene…
Guiceを使ったDependency Injection(依存性の注入)Writing factories and dependency injection logic by hand for every service and client can become tedious. Some other dependency injection frameworks even require you to explicitly map servic…
手作業でのDependency InjectionThe dependency injection pattern aims in part to make unit testing easier. We don't necessarily need a specialized framework to practice dependency injection. You can get roughly 80% of the benefit writing cod…
BENCHMARK関数が、SQLのパフォーマンスチューニングに便利だ。「5.2. SELECT ステートメントおよびその他のクエリの最適化」 mysql> SELECT BENCHMARK(1000000,1+1); + BENCHMARK(1000000,1+1) + 0 + 1 row in set (0.32 sec)これは、PentiumII 400MHz 上で …
プレーン・オールド・ファクトリーBefore we discovered dependency injection, we mostly used the factory pattern. In addition to the service interface, you have a service factory which provides the service to clients as well as a way for test…
Guice 1.0 User's GuideGuice (pronounced "juice") is an ultra-lightweight, next-generation dependency injection container for Java 5 and later.Guiceは、超軽量の次世代Dependency Injectionコンテナで、Java 5以降で動きます。 id:shot6さんが一覧…
よく忘れるので記録。ユーザー・パスが以下の場合 user: root pass: root 以下のコマンドで、すべてのデータベースのDumpスクリプトが保存される。 mysqldump -A -u root -proot -Q --opt -r c:\mysql.dump復元は以下。 mysql -u root -proot test mysql.dump
Group By 節に含まれないカラムをSelect句で表示するとmin(カラム)と同じ結果になる。 MySQLのリファレンス「■6.3.7.3. 非表示のフィールドに対する GROUP BY」より MySQL では GROUP BY の使用を拡張しています。GROUP BY 部分にないカラムや計算を SELECT …
実行時We can now use the injector we created during the first stage to inject objects and introspect on our bindings. Guice's runtime model consists of an injector which contains some number of bindings.これで、オブジェクトを注入したり、バ…
起動時You configure Guice by implementing Module. You pass Guice a module, Guice passes your module a Binder, and your module uses the binder to configure bindings. A binding most commonly consists of a mapping between an interface and a c…
アーキテクチャの概要We can break Guice's architecture down into two distinct stages: startup and runtime. You build an Injector during startup and use it to inject objects at runtime.Guiceのアーキテクチャは、2つの別々のステージに分離するこ…