Author: limpbizkit
Date: Mon Mar  2 21:05:27 2009
New Revision: 892

Added:
    wiki/ProvidesMethods.wiki

Log:
Created wiki page through web user interface.

Added: wiki/ProvidesMethods.wiki
==============================================================================
--- (empty file)
+++ wiki/ProvidesMethods.wiki   Mon Mar  2 21:05:27 2009
@@ -0,0 +1,28 @@
+...@provides Methods=
+When you need code to create an object, use an `...@provides` method. The  
method must be defined within a module, and it must have an `...@provides`  
annotation. The method's return type is the bound type. Whenever the  
injector needs an instance of that type, it will invoke the method.
+{{{
+public class BillingModule extends AbstractModule {
+  @Override
+  protected void configure() {
+    ...
+  }
+
+  @Provides
+  TransactionLog provideTransactionLog() {
+    DatabaseTransactionLog transactionLog = new DatabaseTransactionLog();
+    transactionLog.setJdbcUrl("jdbc:mysql://localhost/pizza");
+    transactionLog.setThreadPoolSize(30);
+    return transactionLog;
+  }
+}
+}}}
+If the `...@provides` method has a binding annotation like `...@paypal` or  
`...@named("Checkout")`, Guice binds the annotated type. Dependencies can be  
passed in as parameters to the method. The injector will exercise the  
bindings for each of these before invoking the method.
+{{{
+  @Provides @PayPal
+  CreditCardProcessor providePayPalCreditCardProcessor(
+      @Named("PayPal API key") String apiKey) {
+    PayPalCreditCardProcessor processor = new PayPalCreditCardProcessor();
+    processor.setApiKey(apiKey);
+    return processor;
+  }
+}}}

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