Author: limpbizkit
Date: Wed May 20 13:04:53 2009
New Revision: 986
Modified:
wiki/Injections.wiki
Log:
Edited wiki page through web user interface.
Modified: wiki/Injections.wiki
==============================================================================
--- wiki/Injections.wiki (original)
+++ wiki/Injections.wiki Wed May 20 13:04:53 2009
@@ -70,10 +70,6 @@
}}}
-==Static Injections==
-TODO
-
-
==requestInjection==
Method and field injection can be used to initialize an existing instance.
You can use the `Injector.injectMembers` API:
{{{
@@ -85,9 +81,32 @@
}}}
+==Static Injections==
+When
[http://publicobject.com/2007/07/guice-patterns-1-horrible-static-code.html
migrating an application] from static factories to Guice, it is possible to
change incrementally. Static injection is a helpful crutch here. It makes
it possible for objects to _partially_ participate in dependency injection,
by gaining access to injected types without being injected themselves. Use
`requestStaticInjection()` in a module to specify classes to be injected at
injector-creation time:
+{{{
+ @Override public void configure() {
+ requestStaticInjection(ProcessorFactory.class);
+ ...
+ }
+}}}
+Guice will inject class's static members that have the `...@injected`
annotation:
+{{{
+class ProcessorFactory {
+ @Inject static Provider<Processor> processorProvider;
+
+ /**
+ * @deprecated prefer to inject your processor instead.
+ */
+ @Deprecated
+ public static Processor getInstance() {
+ return processorProvider.get();
+ }
+}
+}}}
+Static members will not be injected at instance-injection time. This API
is not recommended for general use because it suffers many of the same
problems as static factories: it's clumsy to test, it makes dependencies
opaque, and it relies on global state.
==Automatic Injection==
-TODO
-
-==A Note on Annotations==
-TODO
\ No newline at end of file
+Guice automatically injects all of the following:
+ * instances passed to `toInstance()` in a bind statement
+ * provider instances passed to `toProvider()` in a bind statement
+The objects will be injected while the injector itself is being created.
If they're needed to satisfy other startup injections, Guice will inject
them before they're used.
\ 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
-~----------~----~----~----~------~----~------~--~---