Author: limpbizkit
Date: Mon Mar 2 21:03:07 2009
New Revision: 889
Added:
wiki/LinkedBindings.wiki
Log:
Created wiki page through web user interface.
Added: wiki/LinkedBindings.wiki
==============================================================================
--- (empty file)
+++ wiki/LinkedBindings.wiki Mon Mar 2 21:03:07 2009
@@ -0,0 +1,25 @@
+=Linked Bindings=
+Linked bindings map a type to its implementation. This example maps the
interface `TransactionLog` to the implementation `DatabaseTransationLog`:
+{{{
+public class BillingModule extends AbstractModule {
+ @Override
+ protected void configure() {
+ bind(TransactionLog.class).to(DatabaseTransactionLog.class);
+ }
+}
+}}}
+Now, when you call `injector.getInstance(TransactionLog.class)`, or when
the injector encounters a dependency on `TransactionLog`, it will use a
`DatabaseTransactionLog`. Link from a type to any of its subtypes, such as
an implementing class or an extending class. You can even link the concrete
`DatabaseTransactionLog` class to a subclass:
+{{{
+
bind(DatabaseTransactionLog.class).to(MySqlDatabaseTransactionLog.class);
+}}}
+Linked bindings can also be chained:
+{{{
+public class BillingModule extends AbstractModule {
+ @Override
+ protected void configure() {
+ bind(TransactionLog.class).to(DatabaseTransactionLog.class);
+
bind(DatabaseTransactionLog.class).to(MySqlDatabaseTransactionLog.class);
+ }
+}
+}}}
+In this case, when a `TransactionLog` is requested, the injector will
return a `MySqlDatabaseTransactionLog`.
\ 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
-~----------~----~----~----~------~----~------~--~---