<?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: Say no to ServiceLocator</title>
	<atom:link href="http://blog.vuscode.com/malovicn/archive/2009/10/20/say-no-to-servicelocator.aspx/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.vuscode.com/malovicn/archive/2009/10/20/say-no-to-servicelocator.aspx</link>
	<description>Coding dreams since 1998!</description>
	<lastBuildDate>Thu, 17 Jan 2013 18:15:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: The Service locator pattern is evil &#124; Tom de Koning</title>
		<link>http://blog.vuscode.com/malovicn/archive/2009/10/20/say-no-to-servicelocator.aspx#comment-287</link>
		<dc:creator>The Service locator pattern is evil &#124; Tom de Koning</dc:creator>
		<pubDate>Mon, 04 Apr 2011 15:25:43 +0000</pubDate>
		<guid isPermaLink="false">http://#comment-287</guid>
		<description><![CDATA[[...] are many references why this should be avoided (see here, here and here) , but I think the one reason why you should not do it is testability. You should be able to mock [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] are many references why this should be avoided (see here, here and here) , but I think the one reason why you should not do it is testability. You should be able to mock [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Dingwall</title>
		<link>http://blog.vuscode.com/malovicn/archive/2009/10/20/say-no-to-servicelocator.aspx#comment-286</link>
		<dc:creator>Richard Dingwall</dc:creator>
		<pubDate>Mon, 26 Oct 2009 11:35:43 +0000</pubDate>
		<guid isPermaLink="false">http://#comment-286</guid>
		<description><![CDATA[&lt;p&gt;I agree that dependency injection via construction is the way to go, but there are still a few situation in our apps where we either A) don&#039;t control the objects lifetime or B) have to provide a default constructor. In these situations I see no harm in using common service locator.&lt;/p&gt;
]]></description>
		<content:encoded><![CDATA[<p>I agree that dependency injection via construction is the way to go, but there are still a few situation in our apps where we either A) don&#39;t control the objects lifetime or B) have to provide a default constructor. In these situations I see no harm in using common service locator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cowgaR</title>
		<link>http://blog.vuscode.com/malovicn/archive/2009/10/20/say-no-to-servicelocator.aspx#comment-285</link>
		<dc:creator>cowgaR</dc:creator>
		<pubDate>Wed, 21 Oct 2009 15:12:01 +0000</pubDate>
		<guid isPermaLink="false">http://#comment-285</guid>
		<description><![CDATA[&lt;p&gt;Both of your recent articles are just awesome (I’m browsing your blog now), just prove ne what I have been &quot;following&quot; in my code without ever realizing that I can go &quot;the other way around&quot;, which would be wrong indeed...why to complicate my life?&lt;/p&gt;
&lt;p&gt;I ended using &quot;your laws&quot; in background by digging into the SOLID code principles, where eventually you&#039;ll end with constructors having resolvable parameters (of their dependencies) passed by interfaces, on which instantiation you’ll chose some IoC/Di container to easy your life...(writing new (new ...(new...) at top of your call just doesn’t make sense)&lt;/p&gt;
&lt;p&gt;All of this wouldn&#039;t be needed, if coders would follow SOLID (code to abstractions rather than to implementations etc..) from the start of a Greenfield project, but I understand we live in a real world...&lt;/p&gt;
&lt;p&gt;It needs explanation and big attention once project is heavy in production and refactoring &#160;(due to bad coding practices) has become inevitable...&lt;/p&gt;
&lt;p&gt;Once again, thank you very much for your time and evangelism to good code practices, hope Joel would listen x)&lt;/p&gt;
]]></description>
		<content:encoded><![CDATA[<p>Both of your recent articles are just awesome (I’m browsing your blog now), just prove ne what I have been &quot;following&quot; in my code without ever realizing that I can go &quot;the other way around&quot;, which would be wrong indeed&#8230;why to complicate my life?</p>
<p>I ended using &quot;your laws&quot; in background by digging into the SOLID code principles, where eventually you&#39;ll end with constructors having resolvable parameters (of their dependencies) passed by interfaces, on which instantiation you’ll chose some IoC/Di container to easy your life&#8230;(writing new (new &#8230;(new&#8230;) at top of your call just doesn’t make sense)</p>
<p>All of this wouldn&#39;t be needed, if coders would follow SOLID (code to abstractions rather than to implementations etc..) from the start of a Greenfield project, but I understand we live in a real world&#8230;</p>
<p>It needs explanation and big attention once project is heavy in production and refactoring &nbsp;(due to bad coding practices) has become inevitable&#8230;</p>
<p>Once again, thank you very much for your time and evangelism to good code practices, hope Joel would listen x)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: malovicn</title>
		<link>http://blog.vuscode.com/malovicn/archive/2009/10/20/say-no-to-servicelocator.aspx#comment-284</link>
		<dc:creator>malovicn</dc:creator>
		<pubDate>Wed, 21 Oct 2009 11:54:12 +0000</pubDate>
		<guid isPermaLink="false">http://#comment-284</guid>
		<description><![CDATA[&lt;p&gt;As for using the UserRepository userRepository = new UserRepository() as a way of removing the need for IoC container -&gt; it just moves the IoC container deeper into the UserRepository where it hurts you in your tests, API discoverability, maintainability etc (as explained in this post)..&lt;/p&gt;
&lt;p&gt;As for var logger &#160;= new Logger(); you can do that even in this example (logger is not having any dependencies) but that is corner case (in this discussion)&lt;/p&gt;
&lt;p&gt;There are two major reasons why you may consider using the this.container.Resolve (container is the Facade you mention):&lt;/p&gt;
&lt;p&gt;1. You have in real world quite often this case&lt;/p&gt;
&lt;p&gt;ClassA depends on ClassB&lt;/p&gt;
&lt;p&gt;ClassB depends on ClassC&lt;/p&gt;
&lt;p&gt;ClassC depends on ClassD&lt;/p&gt;
&lt;p&gt;If you follow the rule of explicit ctor dependencies (law #3) you would end in your code (if you don&#039;t use the container to resolve with this)&lt;/p&gt;
&lt;p&gt;new ClassA(new classB(new ClassC(new ClassD()))))&lt;/p&gt;
&lt;p&gt;Which violates the encapsulation by leaking the internals of the class B to place where class A is consumed&lt;/p&gt;
&lt;p&gt;Another variation of this problem can be seen if you imagine that the dependency class depends on IOC service in which case you end with&lt;/p&gt;
&lt;p&gt;new ClassA(container.Resolve&lt;ISomething&gt;())&lt;/p&gt;
&lt;p&gt;There are ways you can go around this: poor man dependency injection, opaque service locator etc but as my blog posts show I&#039;m not very fond of them based on my past experience in using them.&lt;/p&gt;
&lt;p&gt;2. Opaque introducing of AOP &lt;/p&gt;
&lt;p&gt;Every IoC major container has interceptors which allow you adding aspects upon resolution enabling very interesting combinations (check out Ayende’s example &lt;a href=&quot;http://tinyurl.com/eventbrok&quot; target=&quot;_new&quot; rel=&quot;nofollow&quot;&gt;http://tinyurl.com/eventbrok&lt;/a&gt;))&lt;/p&gt;
&lt;p&gt;3. SoCSRP etc&lt;/p&gt;
&lt;p&gt;Let IoC container do what he is supposed to do (building the object graph in this case) and our entities to do what they are supposed to do (business logic only)&lt;/p&gt;
&lt;p&gt;&#160;&lt;/p&gt;
&lt;p style=&quot;MARGIN:0in 0in 10pt;&quot; class=&quot;MsoNormal&quot;&gt;&lt;font size=&quot;3&quot; face=&quot;Calibri&quot;&gt;As for the inheritance scenario (Logger, EmailLogger etc) I have in my queue already a blog post showing my take on that (IoC combined with attributed ctor parameters) &lt;/font&gt;&lt;/p&gt;]]></description>
		<content:encoded><![CDATA[<p>As for using the UserRepository userRepository = new UserRepository() as a way of removing the need for IoC container -&gt; it just moves the IoC container deeper into the UserRepository where it hurts you in your tests, API discoverability, maintainability etc (as explained in this post)..</p>
<p>As for var logger &nbsp;= new Logger(); you can do that even in this example (logger is not having any dependencies) but that is corner case (in this discussion)</p>
<p>There are two major reasons why you may consider using the this.container.Resolve (container is the Facade you mention):</p>
<p>1. You have in real world quite often this case</p>
<p>ClassA depends on ClassB</p>
<p>ClassB depends on ClassC</p>
<p>ClassC depends on ClassD</p>
<p>If you follow the rule of explicit ctor dependencies (law #3) you would end in your code (if you don&#39;t use the container to resolve with this)</p>
<p>new ClassA(new classB(new ClassC(new ClassD()))))</p>
<p>Which violates the encapsulation by leaking the internals of the class B to place where class A is consumed</p>
<p>Another variation of this problem can be seen if you imagine that the dependency class depends on IOC service in which case you end with</p>
<p>new ClassA(container.Resolve&lt;ISomething&gt;())</p>
<p>There are ways you can go around this: poor man dependency injection, opaque service locator etc but as my blog posts show I&#39;m not very fond of them based on my past experience in using them.</p>
<p>2. Opaque introducing of AOP </p>
<p>Every IoC major container has interceptors which allow you adding aspects upon resolution enabling very interesting combinations (check out Ayende’s example <a href="http://tinyurl.com/eventbrok" target="_new" rel="nofollow">http://tinyurl.com/eventbrok</a>))</p>
<p>3. SoCSRP etc</p>
<p>Let IoC container do what he is supposed to do (building the object graph in this case) and our entities to do what they are supposed to do (business logic only)</p>
<p>&nbsp;</p>
<p style="MARGIN:0in 0in 10pt;" class="MsoNormal"><font size="3" face="Calibri">As for the inheritance scenario (Logger, EmailLogger etc) I have in my queue already a blog post showing my take on that (IoC combined with attributed ctor parameters) </font></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Radenko Zec</title>
		<link>http://blog.vuscode.com/malovicn/archive/2009/10/20/say-no-to-servicelocator.aspx#comment-283</link>
		<dc:creator>Radenko Zec</dc:creator>
		<pubDate>Tue, 20 Oct 2009 19:46:57 +0000</pubDate>
		<guid isPermaLink="false">http://#comment-283</guid>
		<description><![CDATA[&lt;p&gt;I could not agree with you in all cases. I also using same method that you have described in this article but in some cases you need to have some facade pattern in code.&lt;/p&gt;
&lt;p&gt;If you are building dll that someone else will consume &lt;/p&gt;
&lt;p&gt;for example is much cleaner to have &lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;Bootstraper.SetUp(); &#160;&lt;/p&gt;
&lt;p&gt;UserRepository userRepository = new UserRepository(); &#160;&lt;/p&gt;
&lt;p&gt;userRepository.Delete(3); &#160;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;and not use any IOC container.&lt;/p&gt;
&lt;p&gt;And if you are building classes that some other programmers will consume is much better to have Facade pattern rather than having dependencies in constructor.&lt;/p&gt;
&lt;p&gt;For example if I have class for Logging errors that log error in Database, send Email to developer and log error in text file I think that is much better to have call like this without any call to IOC container:&lt;/p&gt;
&lt;p&gt; Bootstraper.SetUp(); &#160;&lt;/p&gt;
&lt;p&gt;ILogger logger=new Logger();&lt;/p&gt;
&lt;p&gt;logger.Log(&quot;error message&quot;);&lt;/p&gt;
&lt;p&gt;rather then&lt;/p&gt;
&lt;p&gt;Bootstraper.SetUp(); &#160;&lt;/p&gt;
&lt;p&gt;IContainer cont = UnityContainer.Instance(); &#160;&lt;/p&gt;
&lt;p&gt;ILogger logger=unityContainer.Resolve&lt;Logger&gt;(); &#160;&lt;/p&gt;
&lt;p&gt;logger.Log(&quot;error message&quot;)&lt;/p&gt;
&lt;p&gt;On the other hand I will create classes on lower levels like &lt;/p&gt;
&lt;p&gt;DatabaseLogger or EmailLogger same way that you have described here if they have some dependency classes.&lt;/p&gt;
&lt;p&gt;What do you think?&lt;/p&gt;
]]></description>
		<content:encoded><![CDATA[<p>I could not agree with you in all cases. I also using same method that you have described in this article but in some cases you need to have some facade pattern in code.</p>
<p>If you are building dll that someone else will consume </p>
<p>for example is much cleaner to have </p>
<p>{</p>
<p>Bootstraper.SetUp(); &nbsp;</p>
<p>UserRepository userRepository = new UserRepository(); &nbsp;</p>
<p>userRepository.Delete(3); &nbsp;</p>
<p>}</p>
<p>and not use any IOC container.</p>
<p>And if you are building classes that some other programmers will consume is much better to have Facade pattern rather than having dependencies in constructor.</p>
<p>For example if I have class for Logging errors that log error in Database, send Email to developer and log error in text file I think that is much better to have call like this without any call to IOC container:</p>
<p> Bootstraper.SetUp(); &nbsp;</p>
<p>ILogger logger=new Logger();</p>
<p>logger.Log(&quot;error message&quot;);</p>
<p>rather then</p>
<p>Bootstraper.SetUp(); &nbsp;</p>
<p>IContainer cont = UnityContainer.Instance(); &nbsp;</p>
<p>ILogger logger=unityContainer.Resolve&lt;Logger&gt;(); &nbsp;</p>
<p>logger.Log(&quot;error message&quot;)</p>
<p>On the other hand I will create classes on lower levels like </p>
<p>DatabaseLogger or EmailLogger same way that you have described here if they have some dependency classes.</p>
<p>What do you think?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dalibor Carapic</title>
		<link>http://blog.vuscode.com/malovicn/archive/2009/10/20/say-no-to-servicelocator.aspx#comment-282</link>
		<dc:creator>Dalibor Carapic</dc:creator>
		<pubDate>Tue, 20 Oct 2009 16:40:50 +0000</pubDate>
		<guid isPermaLink="false">http://#comment-282</guid>
		<description><![CDATA[&lt;p&gt;Great post and I think you did a great job of pointing out the benefits of DI through constructor rather then through properties.&lt;/p&gt;
&lt;p&gt;How would you handle the scenario when your business class/entity wants to create another business class on its own? It would still be coupled with the container since you would have to create/resolve this new class through the container.&lt;/p&gt;
&lt;p&gt;Would some sort of aspect framework be better for initializing new entities, can it even be done? &lt;/p&gt;
]]></description>
		<content:encoded><![CDATA[<p>Great post and I think you did a great job of pointing out the benefits of DI through constructor rather then through properties.</p>
<p>How would you handle the scenario when your business class/entity wants to create another business class on its own? It would still be coupled with the container since you would have to create/resolve this new class through the container.</p>
<p>Would some sort of aspect framework be better for initializing new entities, can it even be done? </p>
]]></content:encoded>
	</item>
</channel>
</rss>
