Author: limpbizkit
Date: Tue May 19 02:14:21 2009
New Revision: 972
Modified:
wiki/CustomInjections.wiki
Log:
Edited wiki page through web user interface.
Modified: wiki/CustomInjections.wiki
==============================================================================
--- wiki/CustomInjections.wiki (original)
+++ wiki/CustomInjections.wiki Tue May 19 02:14:21 2009
@@ -1,10 +1,10 @@
#summary Performing custom injections with type and injection listeners
=Custom Injections=
-In addition to the standard `...@inject`-driven injections, guice includes
hooks for custom injections. This enables Guice to host other frameworks
that have their own injection semantics or annotations. Most developers
won't use custom injections directly; but they may see their use in
extensions and third-party libraries. Each custom injection requires a type
listener, an injection listener, and registration of each.
+In addition to the standard `...@inject`-driven injections, Guice includes
hooks for custom injections. This enables Guice to host other frameworks
that have their own injection semantics or annotations. Most developers
won't use custom injections directly; but they may see their use in
extensions and third-party libraries. Each custom injection requires a type
listener, an injection listener, and registration of each.
-[http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/spi/TypeListener.html
TypeListeners]
get notified of the types that Guice injects. Since type
listeners are only notified once-per-type, they are the best place to run
potentially slow operations, such as enumerating a type's members. With
their inspection complete, type listeners may register instance listeners
for values that get injected.
+[http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/spi/TypeListener.html
TypeListeners]
get notified of the types that Guice injects. Since type
listeners are only notified once-per-type, they are the best place to run
potentially slow operations, such as enumerating a type's members. With
their inspection complete, type listeners may register instance listeners
for values as they're injected.
-[http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/MembersInjector.html
MembersInjectors]
and
[http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/spi/InjectionListener.html
InjectionListeners] can be used to receive a callback after Guice has
injected an instance. The instance is injected by Guice, then the members
injectors are notified, and finally the injection listeners are notified.
Since they're notified once-per-instance, these should execute as quickly
as possible.
+[http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/MembersInjector.html
MembersInjectors]
and
[http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/spi/InjectionListener.html
InjectionListeners] can be used to receive a callback after Guice has
injected an instance. The instance is first injected by Guice, then by the
custom members injectors, and finally the injection listeners are notified.
Since they're notified once-per-instance, these should execute as quickly
as possible.
==Example: Injecting a Log4J Logger==
Guice includes built-in support for injecting `java.util.Logger` instances
that are named using the type of the injected instance. With the type
listener API, you can inject a `org.apache.log4j.Logger` with the same
high-fidelity naming. We'll be injecting fields of this format:
@@ -18,7 +18,7 @@
...
}
}}}
-We start by registering our custom type listener `Log4JTypeListener` in a
module:
+We start by registering our custom type listener `Log4JTypeListener` in a
module. We use a matcher to select which types we listen for:
{{{
@Override protected void configure() {
bindListener(Matchers.any(), new Log4JTypeListener());
@@ -37,7 +37,7 @@
}
}
}}}
-Finally, implement the `Log4JMembersInjector` to set the logger. We always
set the field to the same instance here. In your application you may need
to compute a value or request one from a Guice provider.
+Finally, we implement the `Log4JMembersInjector` to set the logger. In
this examle, we always set the field to the same instance. In your
application you may need to compute a value or request one from a provider.
{{{
class Log4JMembersInjector<T> implements MembersInjector<T> {
private final Field field;
@@ -57,5 +57,4 @@
}
}
}
-}}}
-
+}}}
\ No newline at end of file
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en
-~----------~----~----~----~------~----~------~--~---