You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/04/03 13:10:43 UTC
svn commit: r1088253 -
/commons/proper/discovery/trunk/src/site/xdoc/best-practices.xml
Author: simonetripodi
Date: Sun Apr 3 11:10:42 2011
New Revision: 1088253
URL: http://svn.apache.org/viewvc?rev=1088253&view=rev
Log:
added DI framework integration sample, using Guice
Modified:
commons/proper/discovery/trunk/src/site/xdoc/best-practices.xml
Modified: commons/proper/discovery/trunk/src/site/xdoc/best-practices.xml
URL: http://svn.apache.org/viewvc/commons/proper/discovery/trunk/src/site/xdoc/best-practices.xml?rev=1088253&r1=1088252&r2=1088253&view=diff
==============================================================================
--- commons/proper/discovery/trunk/src/site/xdoc/best-practices.xml (original)
+++ commons/proper/discovery/trunk/src/site/xdoc/best-practices.xml Sun Apr 3 11:10:42 2011
@@ -29,6 +29,7 @@ $Id$<br />
<a href="#Additional Tools">[Additional Tools]</a>
<a href="#Calling Directly">[Calling Directly]</a>
<a href="#Integrating into Factories : Wrapping">[Integrating into Factories : Wrapping]</a>
+ <a href="#Integrating into DI framework: Google Guice">[Integrating into DI framework: Google Guice]</a>
<br /><br />
@@ -243,6 +244,32 @@ In this example, they are the same class
is providing helper methods that 'wrap' <code>Discovery</code>.
</p>
+<a name="Integrating into DI framework: Google Guice"></a>
+<h4>3.2 INTEGRATING INTO DI FRAMEWORKS : GOOGLE GUICE</h4>
+
+<p>Sometimes, a <code>DiscoverSingleton</code>/<code>Factory</code> approach like the one exposed above,
+is not enough, because you may require injecting dependencies in your discovered SPI.</p>
+
+<p>In this example is shown how <code>DiscoverClass</code> can be useful inside DI framework such
+<i>Google Guice</i>:</p>
+
+<source>
+Injector injector = Guice.createInjector(new AbstractModule() {
+
+ @Override
+ protected void configure() {
+ ...
+ DiscoverClass discoverClass = new DiscoverClass();
+ bind(ServiceInterface.class).to(discoverClass.find(ServiceInterface.class));
+ ...
+ }
+
+});
+</source>
+
+<p>In this way, <code>ServiceInterface</code> discovery is delegated to <i>Commons Discovery</i>,
+but concrete class implementation creation and dependencies injection, to <i>Google Guice</i>.</p>
+
</subsection>
</section>
</body>