tag:blogger.com,1999:blog-4479279983457560946.post4690424717815872057..comments2015-12-21T09:12:38.535-08:00Comments on Guru Meditation: ServiceLocator vs Dependency InjectionBernhard Richterhttp://www.blogger.com/profile/12224724359174112000noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-4479279983457560946.post-10427657593605840202010-09-27T00:34:26.942-07:002010-09-27T00:34:26.942-07:00Oh, we already dealt with that question here and h...Oh, we already dealt with that question <a href="http://blog.ploeh.dk/2010/01/20/RebuttalConstructorOverinjectionAntipattern.aspx" rel="nofollow">here</a> and <a href="http://blog.ploeh.dk/2010/01/20/EnablingDIForLazyComponents.aspx" rel="nofollow">here</a> :)ploehhttps://www.blogger.com/profile/08123428416238770895noreply@blogger.comtag:blogger.com,1999:blog-4479279983457560946.post-17913724779488730672010-09-24T01:16:29.312-07:002010-09-24T01:16:29.312-07:00I see what you mean and I also see how pure DI can...I see what you mean and I also see how pure DI can make the overall design of the application better.<br /><br />On the other hand, I would like to go back to the example and ask this:<br /><br />Isn't it unnecessary to eagerly create <b>OrderProcessor</b> and <b>OrderShipper</b> instances if the order is not valid?<br /><br />I just sometimes feel that dependencies should not always share the same "lifecycle" as the injection target.<br /><br />What do you think?Bernhard Richterhttps://www.blogger.com/profile/12224724359174112000noreply@blogger.comtag:blogger.com,1999:blog-4479279983457560946.post-79835658013027734142010-09-23T06:07:35.160-07:002010-09-23T06:07:35.160-07:00Thanks for posting this.
The reason I didn't ...Thanks for posting this.<br /><br />The reason I didn't show the idiomatically correct ways to implement OrderProcessor was that it was <a href="http://blog.ploeh.dk/2010/02/02/RefactoringToAggregateServices.aspx" rel="nofollow">ground I had already covered at that time</a>.<br /><br />Cross-cutting concerns, such as logging, are <a href="http://blog.ploeh.dk/2010/04/07/DependencyInjectionIsLooseCoupling.aspx" rel="nofollow">better implemented as Decorators</a> unless you choose to <a href="http://blog.ploeh.dk/2010/09/20/InstrumentationWithDecoratorsAndInterceptors.aspx" rel="nofollow">go all the way and use dynamic Interception</a>. <br /><br />However, I certainly agree that the entire object graph quickly becomes complex, which is why use of a good DI Container is very helpful - but remember: <a href="http://blog.ploeh.dk/2010/08/30/DontCallTheContainerItllCallYou.aspx" rel="nofollow">don't call the container; it'll call you</a> :)ploehhttps://www.blogger.com/profile/08123428416238770895noreply@blogger.com