Revision: 1409
Author: sberlin
Date: Sat Nov 20 20:44:35 2010
Log: Edited wiki page AssistedInject through web user interface.
http://code.google.com/p/google-guice/source/detail?r=1409

Modified:
 /wiki/AssistedInject.wiki

=======================================
--- /wiki/AssistedInject.wiki   Sat May 22 19:29:03 2010
+++ /wiki/AssistedInject.wiki   Sat Nov 20 20:44:35 2010
@@ -62,13 +62,48 @@
 }
 }}}
 Then bind a `Provider<Factory>` in the Guice module:
+==!AssistedInject in Guice 2.0==
 {{{
 bind(PaymentFactory.class).toProvider(
     FactoryProvider.newFactory(PaymentFactory.class, RealPayment.class));
 }}}
-The `FactoryProvider` maps the `create()` method's parameters to the corresponding `...@assisted` parameters in the implementation class' constructor. For the other constructor arguments, it asks the regular Injector to provide values.
-
-With `FactoryProvider`, it's easier to create classes that need extra arguments at construction time:
+
+==!AssistedInject in Guice 3.0==
+Guice 3.0 improves !AssistedInject by offering the ability to allow different factory methods to return different types or different constructors from one type. See the [http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/assistedinject/FactoryModuleBuilder.html FactoryModuleBuilder javadoc] for complete details.
+{{{
+install(new FactoryModuleBuilder()
+     .implement(Payment.class, RealPayment.class)
+     .build(PaymentFactory.class));
+}}}
+
+
+!AssistedInject maps the `create()` method's parameters to the corresponding `...@assisted` parameters in the implementation class' constructor. For the other constructor arguments, it asks the regular Injector to provide values.
+
+With !AssistedInject, it's easier to create classes that need extra arguments at construction time: # Annotate the constructor and assisted parameters on the implementation class (such as `RealPayment`) # Create a factory interface with a `create()` method that takes only the assisted parameters. Make sure they're in the same order as in the constructor
-  # Bind that factory to a provider created by `FactoryProvider`.
+  # Bind that factory to a provider created by !AssistedInject.
+
+==Inspecting !AssistedInject Bindings _(new in Guice 3.0)_==
+
+Visiting an assisted inject binding is useful for tests or debugging. !AssistedInject uses the [ExtensionSPI extensions SPI] to let you learn more about the factory binding. You can visit bindings with an [http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/assistedinject/AssistedInjectTargetVisitor.html AssistedInjectTargetVisitor] to see details about the binding.
+
+{{{
+ Binding<PaymentFactory> binding = injector.getBinding(PaymentFactory.class);
+  binding.acceptTargetVisitor(new Visitor());
+
+  class Visitor
+      extends DefaultBindingTargetVisitor<Object, Void>
+      implements AssistedInjectTargetVisitor<Object, Void> {
+
+    @Override void visit(AssistedInjectBinding<?> binding) {
+      // Loop over each method in the factory...
+      for(AssistedMethod method : binding.getAssistedMethods()) {
+ System.out.println("Non-assisted Dependencies: " + method.getDependencies()
+                       + ", Factory Method: " + method.getFactoryMethod()
+ + ", Implementation Constructor: " + method.getImplementationConstructor() + + ", Implementation Type: " + method.getImplementationType());
+      }
+    }
+  }
+}}}

--
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.

Reply via email to