<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Dependency Injection with Google Guice by example</title>
	<atom:link href="http://dev.eek.be/2009/09/dependency-injection-with-google-guice/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/</link>
	<description>IT knowledge exchange</description>
	<lastBuildDate>Thu, 22 Jul 2010 15:53:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Plata</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/comment-page-1/#comment-19242</link>
		<dc:creator>Plata</dc:creator>
		<pubDate>Wed, 19 May 2010 20:54:47 +0000</pubDate>
		<guid isPermaLink="false">http://dev.eek.be/?p=66#comment-19242</guid>
		<description>Google guice is cool!</description>
		<content:encoded><![CDATA[<p>Google guice is cool!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dependency injection with Groovy and Google Guice</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/comment-page-1/#comment-19238</link>
		<dc:creator>Dependency injection with Groovy and Google Guice</dc:creator>
		<pubDate>Tue, 18 May 2010 13:16:08 +0000</pubDate>
		<guid isPermaLink="false">http://dev.eek.be/?p=66#comment-19238</guid>
		<description>[...] This is just a quick overview of Guice and there is probably quite a bit more I haven&#8217;t discovered yet. I need to give credit to the guy over at dev.eek.be who has written up a great introductory Guice tutorial. [...]</description>
		<content:encoded><![CDATA[<p>[...] This is just a quick overview of Guice and there is probably quite a bit more I haven&#8217;t discovered yet. I need to give credit to the guy over at dev.eek.be who has written up a great introductory Guice tutorial. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JD</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/comment-page-1/#comment-17107</link>
		<dc:creator>JD</dc:creator>
		<pubDate>Fri, 05 Mar 2010 03:28:41 +0000</pubDate>
		<guid isPermaLink="false">http://dev.eek.be/?p=66#comment-17107</guid>
		<description>This is a pretty good tutorial.  Had me thinking about how to apply Guice to my own projects within minutes.</description>
		<content:encoded><![CDATA[<p>This is a pretty good tutorial.  Had me thinking about how to apply Guice to my own projects within minutes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/comment-page-1/#comment-3570</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 27 Oct 2009 15:52:50 +0000</pubDate>
		<guid isPermaLink="false">http://dev.eek.be/?p=66#comment-3570</guid>
		<description>Thank you, implementing the Singleton was the answer!</description>
		<content:encoded><![CDATA[<p>Thank you, implementing the Singleton was the answer!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wim</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/comment-page-1/#comment-3269</link>
		<dc:creator>Wim</dc:creator>
		<pubDate>Mon, 26 Oct 2009 16:52:19 +0000</pubDate>
		<guid isPermaLink="false">http://dev.eek.be/?p=66#comment-3269</guid>
		<description>Hi Mike,

Thanks for your question!
I&#039;m not 100% sure about your question but I think you can accomply this with the use of a Singleton. Luckily, Guice has some some functionality for scopes. Here&#039;s an example.

&lt;b&gt;Main&lt;/b&gt;

&lt;pre class=&quot;prettyprint&quot;&gt;
public class Main {
    public static void main(String[] args) {
        Injector inj = Guice.createInjector(new MyModule());
        Payment pay = inj.getInstance(Payment.class);
        pay.setAmount(&quot;test&quot;);
        System.out.println(pay.getAmount());

        Payment pay2 = inj.getInstance(Payment.class);
        System.out.println(pay2.getAmount());
    }
}
&lt;/pre&gt;

&lt;b&gt;Payment&lt;/b&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
public interface Payment {
    void pay();
    void setAmount(String amount);
    String getAmount();
}
&lt;/pre&gt;

&lt;b&gt;CashPayment&lt;/b&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
public class CashPayment implements Payment {

    private String amount;

    public void pay() {
        System.out.println(&quot;Cash payment&quot;);
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getAmount() {
        return amount;
    }
}
&lt;/pre&gt;

&lt;b&gt;MyModule&lt;/b&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
public class MyModule extends AbstractModule{
    @Override
    protected void configure() {
        bind(Payment.class).to(CashPayment.class).in(Scopes.NO_SCOPE);
    }
}
&lt;/pre&gt;

If you run this code, the output should be 
&lt;pre class=&quot;prettyprint&quot;&gt;
test
null
&lt;/pre&gt;

There are 2 ways to implement the Singleton:
&lt;b&gt;Mymodule&lt;/b&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
public class MyModule extends AbstractModule{
    @Override
    protected void configure() {
        bind(Payment.class).to(CashPayment.class).in(Scopes.SINGLETON);
    }
}
&lt;/pre&gt;
If you run the code again, the result should be
&lt;pre class=&quot;prettyprint&quot;&gt;
test
test
&lt;/pre&gt;

Secondly, you can implement the singleton inside the implenetationclass with an annotation
&lt;pre class=&quot;prettyprint&quot;&gt;

@Singleton
public class CashPayment implements Payment {

    private String amount;

    public void pay() {
        System.out.println(&quot;Cash payment&quot;);
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getAmount() {
        return amount;
    }
}
&lt;/pre&gt;

Hopely, this gives an answer to your question.</description>
		<content:encoded><![CDATA[<p>Hi Mike,</p>
<p>Thanks for your question!<br />
I&#8217;m not 100% sure about your question but I think you can accomply this with the use of a Singleton. Luckily, Guice has some some functionality for scopes. Here&#8217;s an example.</p>
<p><b>Main</b></p>
<pre class="prettyprint">
public class Main {
    public static void main(String[] args) {
        Injector inj = Guice.createInjector(new MyModule());
        Payment pay = inj.getInstance(Payment.class);
        pay.setAmount("test");
        System.out.println(pay.getAmount());

        Payment pay2 = inj.getInstance(Payment.class);
        System.out.println(pay2.getAmount());
    }
}
</pre>
<p><b>Payment</b></p>
<pre class="prettyprint">
public interface Payment {
    void pay();
    void setAmount(String amount);
    String getAmount();
}
</pre>
<p><b>CashPayment</b></p>
<pre class="prettyprint">
public class CashPayment implements Payment {

    private String amount;

    public void pay() {
        System.out.println("Cash payment");
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getAmount() {
        return amount;
    }
}
</pre>
<p><b>MyModule</b></p>
<pre class="prettyprint">
public class MyModule extends AbstractModule{
    @Override
    protected void configure() {
        bind(Payment.class).to(CashPayment.class).in(Scopes.NO_SCOPE);
    }
}
</pre>
<p>If you run this code, the output should be </p>
<pre class="prettyprint">
test
null
</pre>
<p>There are 2 ways to implement the Singleton:<br />
<b>Mymodule</b></p>
<pre class="prettyprint">
public class MyModule extends AbstractModule{
    @Override
    protected void configure() {
        bind(Payment.class).to(CashPayment.class).in(Scopes.SINGLETON);
    }
}
</pre>
<p>If you run the code again, the result should be</p>
<pre class="prettyprint">
test
test
</pre>
<p>Secondly, you can implement the singleton inside the implenetationclass with an annotation</p>
<pre class="prettyprint">

@Singleton
public class CashPayment implements Payment {

    private String amount;

    public void pay() {
        System.out.println("Cash payment");
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getAmount() {
        return amount;
    }
}
</pre>
<p>Hopely, this gives an answer to your question.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/comment-page-1/#comment-3259</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Mon, 26 Oct 2009 16:07:23 +0000</pubDate>
		<guid isPermaLink="false">http://dev.eek.be/?p=66#comment-3259</guid>
		<description>Thank you for this fine article. I have a question, is it possible to overwrite a created instance into the Guice-Bindung during runtime, so that it can be used in other classes?

In your MyModule-Example you have this line:

arg0.bind(Payment.class).to(PaymentCardImpl.class);

now during the usage of the application, i want to do this:

PaymentCardImpl payment = new PaymentCardImpl();
payment.setPay(&quot;currently calculated value&quot;);
injector.OverwriteMyPaymentInstanceIntoGuiceWithThisNewInstance(payment)

When i use injection somewhere else and call getPay, i want to receive my previously stored information.

Is this possible?</description>
		<content:encoded><![CDATA[<p>Thank you for this fine article. I have a question, is it possible to overwrite a created instance into the Guice-Bindung during runtime, so that it can be used in other classes?</p>
<p>In your MyModule-Example you have this line:</p>
<p>arg0.bind(Payment.class).to(PaymentCardImpl.class);</p>
<p>now during the usage of the application, i want to do this:</p>
<p>PaymentCardImpl payment = new PaymentCardImpl();<br />
payment.setPay(&#8220;currently calculated value&#8221;);<br />
injector.OverwriteMyPaymentInstanceIntoGuiceWithThisNewInstance(payment)</p>
<p>When i use injection somewhere else and call getPay, i want to receive my previously stored information.</p>
<p>Is this possible?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steven</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/comment-page-1/#comment-2684</link>
		<dc:creator>steven</dc:creator>
		<pubDate>Sat, 24 Oct 2009 21:07:16 +0000</pubDate>
		<guid isPermaLink="false">http://dev.eek.be/?p=66#comment-2684</guid>
		<description>small thing: you dont have to write public on interfaces</description>
		<content:encoded><![CDATA[<p>small thing: you dont have to write public on interfaces</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anshu Mishra</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/comment-page-1/#comment-2465</link>
		<dc:creator>Anshu Mishra</dc:creator>
		<pubDate>Sat, 24 Oct 2009 03:42:20 +0000</pubDate>
		<guid isPermaLink="false">http://dev.eek.be/?p=66#comment-2465</guid>
		<description>Nice Article. 
I have started writing a series on Google Guice here, planning to add more soon. :-
http://anshu-manymoods.blogspot.com/2009/10/google-guice-part-1.html
http://anshu-manymoods.blogspot.com/2009/10/google-guice-part-2-inject-config-value.html</description>
		<content:encoded><![CDATA[<p>Nice Article.<br />
I have started writing a series on Google Guice here, planning to add more soon. :-<br />
<a href="http://anshu-manymoods.blogspot.com/2009/10/google-guice-part-1.html" rel="nofollow">http://anshu-manymoods.blogspot.com/2009/10/google-guice-part-1.html</a><br />
<a href="http://anshu-manymoods.blogspot.com/2009/10/google-guice-part-2-inject-config-value.html" rel="nofollow">http://anshu-manymoods.blogspot.com/2009/10/google-guice-part-2-inject-config-value.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/comment-page-1/#comment-2154</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Fri, 23 Oct 2009 04:21:45 +0000</pubDate>
		<guid isPermaLink="false">http://dev.eek.be/?p=66#comment-2154</guid>
		<description>Thanks for the post!
looks great</description>
		<content:encoded><![CDATA[<p>Thanks for the post!<br />
looks great</p>
]]></content:encoded>
	</item>
</channel>
</rss>
