<?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: PTOM: The Dependency Inversion Principle</title>
	<atom:link href="http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Wed, 22 May 2013 13:39:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Brian</title>
		<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/#comment-308</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Thu, 21 May 2009 16:50:19 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/03/31/ptom-the-dependency-inversion-principle.aspx#comment-308</guid>
		<description>Great explanation of DIP is here: http://ctrl-shift-b.com/2008/12/examining-dependency-inversion.html </description>
		<content:encoded><![CDATA[<p>Great explanation of DIP is here: <a href="http://ctrl-shift-b.com/2008/12/examining-dependency-inversion.html" rel="nofollow">http://ctrl-shift-b.com/2008/12/examining-dependency-inversion.html</a> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/#comment-307</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Sun, 23 Nov 2008 00:47:02 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/03/31/ptom-the-dependency-inversion-principle.aspx#comment-307</guid>
		<description>I think your last comment is right - not applying DIP to implementations.  It ultimately comes down to how you design your repositories.  Nothing in our app depends on implementations of repositories, so we can put the implementations closer to the &quot;infrastructure&quot; layer, where we have quite a bit of knowledge about the infrastructure we&#039;re using.</description>
		<content:encoded><![CDATA[<p>I think your last comment is right &#8211; not applying DIP to implementations.  It ultimately comes down to how you design your repositories.  Nothing in our app depends on implementations of repositories, so we can put the implementations closer to the &#8220;infrastructure&#8221; layer, where we have quite a bit of knowledge about the infrastructure we&#8217;re using.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/#comment-306</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Sat, 22 Nov 2008 13:52:07 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/03/31/ptom-the-dependency-inversion-principle.aspx#comment-306</guid>
		<description>Okay, but that means that the infrastructure layer would have a logical dependency into the domain layer.
If you use namespaces for partitioning the logical layers (and what else than namespaces could you use for that...?) then we would get this kind of dependency from a repository implementation in the infrastructure layer/namespace to the domain layer/namespace:

namespace DomainLayer {
   public class Customer {
	...
   public interface CustomerRepository {
       Customer FindCustomerById(int id);
	...
   }
	...
}

namespace PersistenceLayer {
   public class CustomerRepositoryImplementedWithNHibernate: DomainLayer.CustomerRepository {
       public DomainLayer.Customer FindCustomerById(int id) {

This is a conflict with what a lot of people think, including Eric Evans as I understand, considering his statement at page 73 in DDD book about the infrastructure layer:
&quot;Being below the domain layer, it should have no specific knowledge of the domain it is serving&quot;

So, what is the appropriate conclusion here...?
(the way I understand it, Eric does not seem to apply the Dependency Inversion Principle for repository implementations...)
</description>
		<content:encoded><![CDATA[<p>Okay, but that means that the infrastructure layer would have a logical dependency into the domain layer.<br />
If you use namespaces for partitioning the logical layers (and what else than namespaces could you use for that&#8230;?) then we would get this kind of dependency from a repository implementation in the infrastructure layer/namespace to the domain layer/namespace:</p>
<p>namespace DomainLayer {<br />
   public class Customer {<br />
	&#8230;<br />
   public interface CustomerRepository {<br />
       Customer FindCustomerById(int id);<br />
	&#8230;<br />
   }<br />
	&#8230;<br />
}</p>
<p>namespace PersistenceLayer {<br />
   public class CustomerRepositoryImplementedWithNHibernate: DomainLayer.CustomerRepository {<br />
       public DomainLayer.Customer FindCustomerById(int id) {</p>
<p>This is a conflict with what a lot of people think, including Eric Evans as I understand, considering his statement at page 73 in DDD book about the infrastructure layer:<br />
&#8220;Being below the domain layer, it should have no specific knowledge of the domain it is serving&#8221;</p>
<p>So, what is the appropriate conclusion here&#8230;?<br />
(the way I understand it, Eric does not seem to apply the Dependency Inversion Principle for repository implementations&#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/#comment-305</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Fri, 21 Nov 2008 00:16:11 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/03/31/ptom-the-dependency-inversion-principle.aspx#comment-305</guid>
		<description>@Peter

Yeah that&#039;s what I meant - implementations of repositories are typically infrastructure.

But ultimately, it doesn&#039;t matter what projects the classes reside in, it matters what uses what.  You could put it all in one project if you like (reduces compile time).  Logical != physical layering.</description>
		<content:encoded><![CDATA[<p>@Peter</p>
<p>Yeah that&#8217;s what I meant &#8211; implementations of repositories are typically infrastructure.</p>
<p>But ultimately, it doesn&#8217;t matter what projects the classes reside in, it matters what uses what.  You could put it all in one project if you like (reduces compile time).  Logical != physical layering.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/#comment-304</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Thu, 20 Nov 2008 23:05:26 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/03/31/ptom-the-dependency-inversion-principle.aspx#comment-304</guid>
		<description>Quote: &quot;Repositories aren&#039;t infrastructure, they&#039;re part of the domain.  _Implementations_ of repositories are. &quot;

Hmm, you start the sentence by saying repositories are not part of the infrastructure (without specifying whether you mean the interface) and then you finish with the word &quot;are&quot; without me being quite sure whether that word refers back to domain or infrastructure, so I am not sure whether you agree or not...

Is this what you mean ?:
Repository INTERFACES are not infrastructure. 
Repository INTERFACES are part of the domain.  IMPLEMENTATIONS of repositories are part of the infrastructure.
</description>
		<content:encoded><![CDATA[<p>Quote: &#8220;Repositories aren&#8217;t infrastructure, they&#8217;re part of the domain.  _Implementations_ of repositories are. &#8221;</p>
<p>Hmm, you start the sentence by saying repositories are not part of the infrastructure (without specifying whether you mean the interface) and then you finish with the word &#8220;are&#8221; without me being quite sure whether that word refers back to domain or infrastructure, so I am not sure whether you agree or not&#8230;</p>
<p>Is this what you mean ?:<br />
Repository INTERFACES are not infrastructure.<br />
Repository INTERFACES are part of the domain.  IMPLEMENTATIONS of repositories are part of the infrastructure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/#comment-303</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Thu, 20 Nov 2008 22:42:12 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/03/31/ptom-the-dependency-inversion-principle.aspx#comment-303</guid>
		<description>@Peter

Repositories aren&#039;t infrastructure, they&#039;re part of the domain.  _Implementations_ of repositories are.  Keep in mind the difference between implementations and abstractions, implementation can come from Kalamazoo, but no one knows about it!</description>
		<content:encoded><![CDATA[<p>@Peter</p>
<p>Repositories aren&#8217;t infrastructure, they&#8217;re part of the domain.  _Implementations_ of repositories are.  Keep in mind the difference between implementations and abstractions, implementation can come from Kalamazoo, but no one knows about it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/#comment-302</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Thu, 20 Nov 2008 20:39:59 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/03/31/ptom-the-dependency-inversion-principle.aspx#comment-302</guid>
		<description>In the code, you do not show any usage of the namespaces. Also, I noted that you mention DDD, so I have a question about how to use layering (namespaces dependencies) when implementing a DDD repository. IMHO, the persistence layer (aka infrastructure layer) would reference the domain layer if you apply DIP. This is quite the opposite what most people think, but according to DIP, I think that is the way it should be done. 
For example, consider these dependencies, look at the &quot;using&quot; and the &quot;namespaces&quot;:

using DomainLayer;
namespace PersistenceLayer {
    public class CustomerRepositoryImplementedWithNHibernate: CustomerRepository {
        public Customer FindCustomerById(int id) {
                ...


namespace DomainLayer {
    public interface CustomerRepository {
        Customer FindCustomerById(int id);
    }
}

namespace DomainLayer {
    public class Customer {
                ...

namespace DomainLayer {
    public class CustomerService {
        public CustomerRepository CustomerRepository { set; get; }
        public void &quot;someMethod()&quot; {
                ...
            Customer customer = CustomerRepository.FindCustomerById(123);
                ...

The fundamental question here is whether this kind of dependency should be allowed:
PersistenceLayer.CustomerRepositoryImplementedWithNHibernate inherits e.g. depends on DomainLayer.CustomerRepository
(the way I comprehend DIP, the answer should be yes, even tough most people would probably spontaneously think that the dependency should be inversed)</description>
		<content:encoded><![CDATA[<p>In the code, you do not show any usage of the namespaces. Also, I noted that you mention DDD, so I have a question about how to use layering (namespaces dependencies) when implementing a DDD repository. IMHO, the persistence layer (aka infrastructure layer) would reference the domain layer if you apply DIP. This is quite the opposite what most people think, but according to DIP, I think that is the way it should be done.<br />
For example, consider these dependencies, look at the &#8220;using&#8221; and the &#8220;namespaces&#8221;:</p>
<p>using DomainLayer;<br />
namespace PersistenceLayer {<br />
    public class CustomerRepositoryImplementedWithNHibernate: CustomerRepository {<br />
        public Customer FindCustomerById(int id) {<br />
                &#8230;</p>
<p>namespace DomainLayer {<br />
    public interface CustomerRepository {<br />
        Customer FindCustomerById(int id);<br />
    }<br />
}</p>
<p>namespace DomainLayer {<br />
    public class Customer {<br />
                &#8230;</p>
<p>namespace DomainLayer {<br />
    public class CustomerService {<br />
        public CustomerRepository CustomerRepository { set; get; }<br />
        public void &#8220;someMethod()&#8221; {<br />
                &#8230;<br />
            Customer customer = CustomerRepository.FindCustomerById(123);<br />
                &#8230;</p>
<p>The fundamental question here is whether this kind of dependency should be allowed:<br />
PersistenceLayer.CustomerRepositoryImplementedWithNHibernate inherits e.g. depends on DomainLayer.CustomerRepository<br />
(the way I comprehend DIP, the answer should be yes, even tough most people would probably spontaneously think that the dependency should be inversed)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jimmy Bogard</title>
		<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/#comment-301</link>
		<dc:creator>Jimmy Bogard</dc:creator>
		<pubDate>Wed, 02 Apr 2008 12:34:05 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/03/31/ptom-the-dependency-inversion-principle.aspx#comment-301</guid>
		<description>@Benny

Strategy means I can swap out implementations of an algorithm.  In this case, I have a &quot;US tax strategy&quot; and a &quot;UK tax strategy&quot;, each of which calculate tax very differently.  But the order processor calculates total the same each time.

I would make a new order processor for each order.  Object creation is very cheap, so I&#039;m not worried about keeping it around.

This code came from a legacy project where the &quot;OrderProcessor&quot; did way more than it should have.  Typically I would move the &quot;CalculateTotal&quot; method to a class that better encapsulates this responsibility.</description>
		<content:encoded><![CDATA[<p>@Benny</p>
<p>Strategy means I can swap out implementations of an algorithm.  In this case, I have a &#8220;US tax strategy&#8221; and a &#8220;UK tax strategy&#8221;, each of which calculate tax very differently.  But the order processor calculates total the same each time.</p>
<p>I would make a new order processor for each order.  Object creation is very cheap, so I&#8217;m not worried about keeping it around.</p>
<p>This code came from a legacy project where the &#8220;OrderProcessor&#8221; did way more than it should have.  Typically I would move the &#8220;CalculateTotal&#8221; method to a class that better encapsulates this responsibility.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BennyXNO</title>
		<link>http://lostechies.com/jimmybogard/2008/03/31/ptom-the-dependency-inversion-principle/#comment-300</link>
		<dc:creator>BennyXNO</dc:creator>
		<pubDate>Wed, 02 Apr 2008 11:30:49 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/03/31/ptom-the-dependency-inversion-principle.aspx#comment-300</guid>
		<description>I see som holes in your &quot;Solution&quot;.

Your orderprocessor takes IDiscountCalculator and a ITaxStrategy as input, but this must be wrong, because of the Strategy for taxes lies in each order and you can&#039;t use the same Strategy for both &quot;US&quot; and &quot;UK&quot; orders. Or do you want to make a new OrderProsessor for each order? This seems somewhat troublesome to me.</description>
		<content:encoded><![CDATA[<p>I see som holes in your &#8220;Solution&#8221;.</p>
<p>Your orderprocessor takes IDiscountCalculator and a ITaxStrategy as input, but this must be wrong, because of the Strategy for taxes lies in each order and you can&#8217;t use the same Strategy for both &#8220;US&#8221; and &#8220;UK&#8221; orders. Or do you want to make a new OrderProsessor for each order? This seems somewhat troublesome to me.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
