<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Ironism &#187; ioc</title>
	<atom:link href="http://www.larsan.net/tag/ioc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.larsan.net</link>
	<description>of Lars J. Nilsson</description>
	<lastBuildDate>Sat, 03 Dec 2011 21:41:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Guice Support in Firebase</title>
		<link>http://www.larsan.net/2010/03/guice-support-in-firebase/</link>
		<comments>http://www.larsan.net/2010/03/guice-support-in-firebase/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 16:46:23 +0000</pubDate>
		<dc:creator>fungrim</dc:creator>
				<category><![CDATA[Firebase]]></category>
		<category><![CDATA[guice]]></category>
		<category><![CDATA[ioc]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/index.php?option=com_wordpress&#038;p=57&#038;Itemid=41</guid>
		<description><![CDATA[I&#8217;ve always wanted to add dependency injection support to Firebase, and today we released a candidate for Guice! And if you ask me, it&#8217;s very cool indeed.The documentation is a bit sparse at the moment, but can be found on our wiki. The rest of the post I&#8217;ll just show how a small fictional game ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always wanted to add dependency injection support to <a href="http://www.cubeia.org/">Firebase</a>, and today we released a candidate for <a href="http://code.google.com/p/google-guice/">Guice</a>! And if you ask me, it&#8217;s very cool indeed.The documentation is a bit sparse at the moment, but can be found on our <a href="http://www.cubeia.org/wiki/index.php/Dev/guice">wiki</a>. The rest of the post I&#8217;ll just show how a small fictional game would look using Guice.To start with, the Guice support comes in a set of abstract base classes, one for each Firebase artefact. And to use those you&#8217;d have to add a dependency to you Maven build (I&#8217;ll assume Maven here, you can of course use whatever you&#8217;d like):
<pre>&lt;dependency&gt;&lt;groupId&gt;com.cubeia.firebase&lt;/groupId&gt;&lt;artifactId&gt;guice-support&lt;/artifactId&gt;&lt;version&gt;1.0-RC.1&lt;/version&gt;&lt;/dependency&gt;</pre>
<p>And if you haven&#8217;t already got it, you&#8217;d need our repository as well:
<pre>&lt;repository&gt;&lt;id&gt;cubeia-nexus&lt;/id&gt;&lt;url&gt;http://m2.cubeia.com/nexus/content/groups/public/&lt;/url&gt;&lt;releases&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/releases&gt;&lt;snapshots&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/snapshots&gt;&lt;/repository&gt;</pre>
<p>Now your all set to go, just extend <em>GuiceGame</em> and return the class of you game processor within the configuration, like so:
<pre>public class MyGame extends GuiceGame {public Configuration getConfigurationHelp() {return new ConfigurationAdapter() {public Class getGameProcessorClass() {return MyProcessor.class;}};}}</pre>
<p>So what&#8217;s the magic then? It is this: The class <em>MyProcessor</em> will be instantiated by Guice and can therefore contain injections. And further, it will be done in a custom scope, per event, thus isolating instances nicely.You can also add your own modules to the injection context, again by overriding a method in <em>GuiceGame</em>:
<pre>protected void preInjectorCreation(List list) {list.add(new MyGameModule());}</pre>
<p>Which means, you can inject not only stuff from the current table but also, your own classes. So if we continue:
<pre>public class MyProcessor implements MyProcessor {/** This is probably configured in the "MyGameModule" configured* in the guice game extension.*/@Injectprivate MyHandler handler;/** This is a speciality, you can inject Firebase services* right into your classes.*/@Serviceprivate ScriptSupport support;/** And another shortcut, if you use Log4j, we have a* a helper annotation for you...*/@Log4jprivate Logger log;public void handle(GameDataAction action, Table table) {// do something here eh?}[...]}</pre>
<p>That should give you the idea. You can inject Firebase services as well as a logger (and remember, if you don&#8217;t use Log4j, Guice support the Java utility logging package from scratch). There&#8217;s a couple of things not shown here, for example, you can inject table members directly into the classes and the state object, so you don&#8217;t have to pass those around.Any catch? Well, when you create your own modules you&#8217;ll need to keep in mind that the processor will only work in a custom scope, called <em>EventScope</em>. So if you have something which needs to be bound not as a singleton or in the default scope, you&#8217;ll probably need to do something like this:
<pre>bind(MyHandler.class).to(MyHandlerImpl.class).in(EventScoped.class);</pre>
<p>And that&#8217;s it! In a few days we&#8217;ll release our script support, which is as you might imagine built on top of the Guice support. And so far? I love it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsan.net/2010/03/guice-support-in-firebase/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Brain Scan</title>
		<link>http://www.larsan.net/2008/11/brain-scan/</link>
		<comments>http://www.larsan.net/2008/11/brain-scan/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 19:55:26 +0000</pubDate>
		<dc:creator>fungrim</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[aop]]></category>
		<category><![CDATA[cep]]></category>
		<category><![CDATA[eda]]></category>
		<category><![CDATA[guice]]></category>
		<category><![CDATA[ioc]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jta]]></category>
		<category><![CDATA[soa]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://fungrim.wordpress.com/?p=395</guid>
		<description><![CDATA[My brain&#8217;s hurting. I must be getting old.For reference, this is some of the programming topics I&#8217;ve read up on (or at least tried) lately: Guice and Spring Declarative transactions and JTA EDA, Pipelines and CEP SOA and ESB and NMR Column databases and distributed file systems Wicket and various related Ajax components OSGi in ]]></description>
			<content:encoded><![CDATA[<p>My brain&#8217;s hurting. I must be getting old.For reference, this is <em>some</em> of the <em>programming</em> topics I&#8217;ve read up on (or at least tried) lately:
<ul>
<li>Guice and Spring</li>
<li>Declarative transactions and JTA</li>
<li>EDA, Pipelines and CEP</li>
<li>SOA and ESB and NMR</li>
<li>Column databases and distributed file systems</li>
<li>Wicket and various related Ajax components</li>
<li>OSGi in various permutations with the above</li>
<li>BI, in-memory BI and CEP (again)</li>
<li>AOP and/or IoC patterns</li>
</ul>
<p>And now I&#8217;m contemplating the fultility of programming.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsan.net/2008/11/brain-scan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google IoC Framework; Apparently released</title>
		<link>http://www.larsan.net/2007/03/google-ioc-framework-apparently-released/</link>
		<comments>http://www.larsan.net/2007/03/google-ioc-framework-apparently-released/#comments</comments>
		<pubDate>Mon, 12 Mar 2007 18:46:35 +0000</pubDate>
		<dc:creator>fungrim</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[guice]]></category>
		<category><![CDATA[ioc]]></category>

		<guid isPermaLink="false">http://fungrim.wordpress.com/2007/03/12/google-ioc-framework-apparently-released/</guid>
		<description><![CDATA[Regarding my last post about Spring. The crazed man himself tells me that Google now have released its own IoC framework. Hum&#8230; I&#8217;ll have to check it out when I get time]]></description>
			<content:encoded><![CDATA[<p>Regarding my last <a href="http://fungrim.wordpress.com/2007/03/11/count-me-in-i-dont-get-spring-either/">post</a> about Spring. The crazed man himself tells me that Google now have <a href="http://crazybob.org/2007/03/guice-10.html">released</a> its own IoC framework. Hum&#8230; I&#8217;ll have to check it out when I get time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsan.net/2007/03/google-ioc-framework-apparently-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Count me in, I don&#8217;t &#8220;get&#8221; Spring either</title>
		<link>http://www.larsan.net/2007/03/count-me-in-i-dont-get-spring-either/</link>
		<comments>http://www.larsan.net/2007/03/count-me-in-i-dont-get-spring-either/#comments</comments>
		<pubDate>Sun, 11 Mar 2007 11:02:10 +0000</pubDate>
		<dc:creator>fungrim</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ioc]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://fungrim.wordpress.com/2007/03/11/count-me-in-i-dont-get-spring-either/</guid>
		<description><![CDATA[Crazy Bob had a post i January which he got a lot of feedback on, namely: I don&#8217;t get Spring. Spring, as in the Java framework of course. He has a lot of specific concerns that I won&#8217;t repeat here, but many of them are good. Introduction I&#8217;m afraid I don&#8217;t &#8220;get&#8221; it either. Religion ]]></description>
			<content:encoded><![CDATA[<p>Crazy Bob had a post i January which he got a lot of feedback on, namely: <a href="http://crazybob.org/2006/01/i-dont-get-spring.html">I don&#8217;t get Spring</a>. Spring, as in the Java framework of course. He has a lot of specific concerns that I won&#8217;t repeat here, but many of them are good.<strong> </strong></p>
<p><strong>Introduction</strong><br />
I&#8217;m afraid I don&#8217;t &#8220;get&#8221; it either. Religion does that to me, as soon as someone tells me if I would only <em>get it</em> I would understand, I automatically back off, ready to fight. I mean, if I only <em>would let</em> Jesus into my life I would start believe, right? And if I would only start <em>getting</em> Spring I would be a follower too, right?</p>
<p>Yeah, right.</p>
<p>You don&#8217;t think it is a religion? Well, try critizising it, and then check what kind of responses you&#8217;ll get. (In fact, have you read a critical analyzis of spring at all? Probably not, I know that I haven&#8217;t. And that worries me, and apparently Crazy Bob as well,  a bit). Or you can read Bobs post and then scan through the comments:</p>
<ul>
<li>&#8220;I use it and it works for me&#8221;</li>
<li>&#8220;If you just get it you would understand&#8221;</li>
<li>&#8220;So? Don&#8217;t use it then&#8221;</li>
</ul>
<p>And many will testify to the fervor with which Spring advocates jumps at any doubting voice. (Also among the comments, there&#8217;s some long sales pitches from <a href="http://www.jroller.com/page/kdonald">Keith</a> from the Spring Web Flow team.)</p>
<p>So why am I sceptical? Well, the religion issue apart, here&#8217;s some things about Spring which I question:</p>
<ul>
<li>It is not very a light-weight sollution</li>
<li>Spring does affect you code</li>
<li>There&#8217;s no clear demarcation between code and XML</li>
<li>Spring XML effectively is another language</li>
<li>Refactoring and debugging becomes a pain</li>
</ul>
<p>Let&#8217;s take them on, shall we?<strong></strong></p>
<p><strong>Heavy Ball and Chain<br />
</strong>Light-weight? Erhm, no, I don&#8217;t think so. Light-weight in my book means small, non-intrusive and without any particular runtime impact. Also, I don&#8217;t expect light-weight sollutions to have any significant impact on my coding style. And let&#8217;s not forget what Bob points out, the public contracts of Spring are very much not light at all (but to their defence, they do have extensive API documentation provided).<strong></strong></p>
<p><strong>Don&#8217;t Touch My Code</strong><br />
Contrary to claims, spring does &#8220;touch&#8221; my code. Just becasuse what injects your dependencies on the right places sits outside your code instead of within it, doesn&#8217;t mean it doesn&#8217;t exist. I mean, how do you start you application? It is correct that no Java code is visible in your project, but this is not necesserally a good thing. And as Bob puts it:</p>
<blockquote><p>Spring advocates tout that Spring doesn&#8217;t &#8220;touch&#8221; your code, i.e. you don&#8217;t have to implement any Spring-specific interfaces (with the exception of life-cycle interfaces, etc.). News flash: the XML configuration *is <em>my code</em>*, and from what I can see it often ends up constituting a <span style="font-style: italic;">lot</span> of code, all of which is Spring-specific.&nbsp;</p></blockquote>
<p><strong>Demarcation</strong><br />
Where do you draw the line between Spring and Java? If you do it too coarse-grained you don&#8217;t particulary need Spring at all, but as you penetrate deeper the amount of XML will grow rapidly, and that will soon become a problem. I have been in projects with fully grown &#8220;XML Hell&#8221; problems. It. Is. Not. Funny.<strong></strong></p>
<p><strong>Mixing Langauges?<br />
</strong>Please read the Bob-qoute a few paragraphs above: XML <em>is code</em> in a Spring project. A &#8220;fully Springified&#8221; project will most probably, thanks to the demarcation problem, have a lot of XML files in a 3rd party language. In other words, in order to fully understand, and therefore effectively work in, such a project you need to be fluent in Spring. Light-weight? No. Does it affect my code? Yes.</p>
<p>Do I really want projects written in two separate lagauges? Perhaps it isn&#8217;t a problem, but you must understand that when you take the Spring step, you are forever relying on dual-language programmers to work on and support it. And large projects tend to live longer than their programmers. That might be a really big problem for any Spring project in the near future. Seriously. What if you can&#8217;t find any good Spring programmers to hire? Legacy code is bad enough. Legacy code in an obscure XML language that no-one really uses any more is even worse.<strong></strong></p>
<p><strong>Hard references and strong types</strong><br />
I like strong types. I like hard references. They make my life as a programmer so much simpler. And both of them are negatively affected by Spring. This problem will shrink a bit when IDE&#8217;s becomes better at handling Spring files for you. But right now, they&#8217;re not up to schratch.</p>
<p><strong>Conclusion</strong><br />
Does this mean I don&#8217;t like dependency injection? Not at all. Good programmers do that all the time without the help of any heavy-weight framework. Does this mean I will never use Spring? Not at all. But I consider the above points very important and unless I&#8217;m wrong, which of course may well be the case, I&#8217;ll probably try to stay away. And to be very, very clear to any Spring zelaot happening to read this: Don&#8217;t bother to answer unless you have answers, they&#8217;re specific, and to the point. I&#8217;m not interested in your religion, I&#8217;m interested in writing damn good code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsan.net/2007/03/count-me-in-i-dont-get-spring-either/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

