<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx</link><description>Long live “Dependency Resolution”! OK, so I’m not really serious – but I got your attention right? Truth is, I personally love Dependency Injection , but that doesn’t mean it isn’t without its flaws. The Service Locator pattern is often touted as Dependency</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8675282</link><pubDate>Tue, 01 Jul 2008 08:24:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8675282</guid><dc:creator>Srikar</dc:creator><description>&lt;p&gt;No matter how you slice it, end of the day it all comes down to one and the same. There will still be overhead.&lt;/p&gt;</description></item><item><title>Dependency Injection is Dead! </title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8675633</link><pubDate>Tue, 01 Jul 2008 09:49:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8675633</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8675854</link><pubDate>Tue, 01 Jul 2008 11:03:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8675854</guid><dc:creator>Simone</dc:creator><description>&lt;p&gt;That's a nice approach... but not that &amp;quot;DI is dead&amp;quot; (as referred to in the DNK title)...&lt;/p&gt;
&lt;p&gt;This is still DI, just injected in a different way: instead of using a IoC container the dependency is injected via an AOP framework...&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8675947</link><pubDate>Tue, 01 Jul 2008 11:25:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8675947</guid><dc:creator>simonince</dc:creator><description>&lt;p&gt;Srikar;&lt;/p&gt;
&lt;p&gt;Yup, you're absolutely right. But writing any software is always about trade-offs of performance against speed of development, good design, features, number of developers, and so on... and I think in a good proportion of cases this is a trade-off worth making. Not every case though, granted!&lt;/p&gt;
&lt;p&gt;Simone;&lt;/p&gt;
&lt;p&gt;I wouldn't deny that - excuse my sense of humour with the post title :-) &amp;nbsp;I do think the approach is different enough to increase the appeal of DI though, and also different enough to warrant a slightly different name to clarify the implications.&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8676098</link><pubDate>Tue, 01 Jul 2008 12:18:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8676098</guid><dc:creator>Nicholas Blumhardt</dc:creator><description>&lt;p&gt;Cool post, Simon.&lt;/p&gt;
&lt;p&gt;Here are my thoughts:&lt;/p&gt;
&lt;p&gt;The biggest problem with Service Locator is not the service locator permeating code, but the dependency upon global state (the state of the service locator.)&lt;/p&gt;
&lt;p&gt;Components that depend on a service locator, whether explicitly or through weaving, aren't fully isolated from their environment. Controlling (and predicting) their behaviour depends on the behaviour of the global service locator.&lt;/p&gt;
&lt;p&gt;The dependencies of components using DI, on the other hand, can be controlled entirely at the point of instantiation.&lt;/p&gt;
&lt;p&gt;Most of the time the responsibility for this lies with the container, but creating and configuring a component outside of the container will always work predictably. This increases the flexibility of the system - it is easy to put existing components to work in new ways.&lt;/p&gt;
&lt;p&gt;Regarding:&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;An object’s consumer shouldn’t need to know that X must be done before Y will work if at all possible.&lt;/p&gt;
&lt;p&gt;I think perhaps the inverse is true - it is better to manage complexity up front than to have it build up behind the scenes. The important thing here is how the API of the component communicates its dependencies. E.g. if X must be done before Y, the X must be done via the constructor.&lt;/p&gt;
&lt;p&gt;I think the approach you've described could be a successful improvement on Service Locator, but it doesn't provide the flexibility or the complexity management you'd get with Dependency Injection. Keen to see where it goes though, I'm sure many more people will want to add their (differing) thoughts on the matter :)&lt;/p&gt;
&lt;p&gt;BTW, several containers - especially &lt;a rel="nofollow" target="_new" href="http://autofac.org"&gt;http://autofac.org&lt;/a&gt; - can use delegates to instantiate components, eliminating the need for reflection, if you like.&lt;/p&gt;
&lt;p&gt;Thanks for the really thoughtful post, looking forwards to reading more!&lt;/p&gt;
&lt;p&gt;Nick&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8677341</link><pubDate>Tue, 01 Jul 2008 17:50:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8677341</guid><dc:creator>Casper Bang</dc:creator><description>&lt;p&gt;Very good post Simon. Personally I am no huge fan of DI as it's hyped as a magic bullet these days - funny enough also by people who do not know about SPI's (the service provider pattern).&lt;/p&gt;
&lt;p&gt;I've used SPI's for years and it assists both in mockup and component-decoupling scenarios. And frankly I like not having to add another framework to the stack. &lt;/p&gt;
&lt;p&gt;As to your issue with service provider, you can simply use a static factory method to hide the lookup part. In fact, if you did this up front (as you're suppose to purists will claim) it's trivial to extend it to be a true SPI without any consequence to existing code.&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8677382</link><pubDate>Tue, 01 Jul 2008 18:01:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8677382</guid><dc:creator>Nate Kohari</dc:creator><description>&lt;p&gt;Interesting idea, but as you say yourself:&lt;/p&gt;
&lt;p&gt;&amp;quot;As if by magic, our application now works.&amp;quot;&lt;/p&gt;
&lt;p&gt;The danger here is that it won't be clear to other developers where the values are coming from. This is a problem with AOP in general -- by relying on post-weaving you give up the declarative nature of your code.&lt;/p&gt;
&lt;p&gt;Also, relying on AOP to inject dependencies will cause maintenance nightmares down the road. Further, I'd argue that this solution doesn't provide the same sort of features a typical DI framework gives you -- things like lifecycle management and more complex type resolution scenarios.&lt;/p&gt;
&lt;p&gt;If you're concerned about reflection, a couple of DI frameworks provide ways around it: &amp;lt;a href=&amp;quot;&lt;a rel="nofollow" target="_new" href="http://ninject.org/&amp;quot;&amp;gt;Ninject&amp;lt;/a&amp;gt;"&gt;http://ninject.org/&amp;quot;&amp;gt;Ninject&amp;lt;/a&amp;gt;&lt;/a&gt; (my framework) uses DynamicMethod to generate delegates that do the injection, and as Nick said above, his autofac framework is entirely geared around delegates.&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8677401</link><pubDate>Tue, 01 Jul 2008 18:07:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8677401</guid><dc:creator>Nate Kohari</dc:creator><description>&lt;p&gt;@Casper:&lt;/p&gt;
&lt;p&gt;The service locator pattern forces you to couple all of your components to the locator. Also, if you want to alter the composition of your application, you have to change the calls to the service locator, meaning you're forced to modify the implementations of your different components.&lt;/p&gt;
&lt;p&gt;The use of static methods in general make your code very inflexible, and the use of a service locator means that you will have static calls in nearly every component of your application.&lt;/p&gt;
&lt;p&gt;Dependency injection provides a non-invasive way to wire up components from the outside, and lets you collect this binding logic in a single deterministic location.&lt;/p&gt;
&lt;p&gt;Anyone hyping DI as a silver bullet is mistaken, but there are clear advantages versus the use of service locators.&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8677532</link><pubDate>Tue, 01 Jul 2008 18:44:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8677532</guid><dc:creator>Ayende Rahien</dc:creator><description>&lt;p&gt;1/ An object’s consumer shouldn’t need to know that X &lt;/p&gt;
&lt;p&gt;That is right, this is why you use an IoC.&lt;/p&gt;
&lt;p&gt;The one place that needs to know about the container is the infrastructure, everything else is constructed by the container.&lt;/p&gt;
&lt;p&gt;2/ When using property injection you generally need to mark your dependencies as public&lt;/p&gt;
&lt;p&gt;Use ctor injection, that is the preferred mode.&lt;/p&gt;
&lt;p&gt;3/ Reflection&lt;/p&gt;
&lt;p&gt;all IoC containers use a heavily optimized approaches, down to generating IL at runtime.&lt;/p&gt;
&lt;p&gt;I have not seen production ready container that had perf problems because of that.&lt;/p&gt;
&lt;p&gt;4/ Large object chains create lot of objects&lt;/p&gt;
&lt;p&gt;Who _cares_ ?&lt;/p&gt;
&lt;p&gt;It takes 0.00000006 ms to create an object in .NET&lt;/p&gt;
&lt;p&gt;This is absolutely insignificant number.&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8677602</link><pubDate>Tue, 01 Jul 2008 18:59:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8677602</guid><dc:creator>Casper Bang</dc:creator><description>&lt;p&gt;@Nate:&lt;/p&gt;
&lt;p&gt;Thanks but correct me if I am wrong, doesn't DI rely on a container to do the injection? If so, is that not as much a dependency as relying on an abstract service provider to do the mediation? At the end of the day, SOMETHING is going to have this binding knowledge.&lt;/p&gt;
&lt;p&gt;Perhaps I have not truly seen all the advantages of DI but some of the stuff I have seen which uses a lot of configuration and reflection is just not worth it, I happen to like it very much when I can do type-safe modeling within the IDE.&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8677621</link><pubDate>Tue, 01 Jul 2008 19:04:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8677621</guid><dc:creator>Casey</dc:creator><description>&lt;p&gt;That looks much worse than even a service locator approach ... the magic is even more hidden ....&lt;/p&gt;
&lt;p&gt;Be explicit ... hiding stuff is not the objective ... &lt;/p&gt;
&lt;p&gt;The same as an IoC container is not the answer to every scenario, AOP especially via weaving is definitely not ... &lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8678112</link><pubDate>Tue, 01 Jul 2008 21:21:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8678112</guid><dc:creator>Frank Quednau</dc:creator><description>&lt;p&gt;&amp;quot;I think some of the AOP libraries could help ... by providing alternative interception models, support for explicitly only targeting properties ..., or better ways of manipulating arguments and return values.&amp;quot;&lt;/p&gt;
&lt;p&gt;I wholeheartedly agree.&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8678175</link><pubDate>Tue, 01 Jul 2008 21:39:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8678175</guid><dc:creator>Jason Olson</dc:creator><description>&lt;p&gt;@Casper&lt;/p&gt;
&lt;p&gt;Casper, it is also about separation of concerns. Individual classes should not have to be concerned with DI, they don't even care how it's done. &lt;/p&gt;
&lt;p&gt;You can also think about it around the Single Responsibility Principle. When using a DI container, the sole responsibility of injecting dependencies lies with the container, not with any classes needing dependencies. &lt;/p&gt;
&lt;p&gt;However, when using a Service Locator, your classes now have to care (and have &amp;quot;expert knowledge&amp;quot;) on where it gets its dependencies from. If you ever change the model of how dependencies are filled (let's say changing the interface of the Service Locator itself), every single class in your application breaks (which definitely breaks the Open-Closed Principle). A static dependency in .NET is about as tight of coupling as you can possibly get. When using a DI container though, the DI container itself can change and won't impact any of the classes. &lt;/p&gt;
&lt;p&gt;This is why I like the DI container approach versus the Service Locator. Classes don't have to know about dependency injection, they're single responsibility is to fulfill their desired behavior. &lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8678193</link><pubDate>Tue, 01 Jul 2008 21:44:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8678193</guid><dc:creator>logicalmind</dc:creator><description>&lt;p&gt;I use spring.net for my DI needs so I am a bit confused by some of the things in this article. A very simple setup would look like this:&lt;/p&gt;
&lt;p&gt;public interface IProvider { void DoSomething(); }&lt;/p&gt;
&lt;p&gt;class ProviderImpl : IProvider&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public void DoSomething() { ... }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;public interface IConsumer { void Go(); }&lt;/p&gt;
&lt;p&gt;class ConsumerImpl : IConsumer&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;private IProvider provider;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public IProvider Provider &lt;/p&gt;
&lt;p&gt; &amp;nbsp;{ set { provider = value; } }&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public void Go() { provider.DoSomething(); }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Note that my implementation classes are not public. Nobody knows what classes my implementation depend on. They simply know and use the interfaces. The dependencies are defined in the config file (uses property injection):&lt;/p&gt;
&lt;p&gt;&amp;lt;object id=&amp;quot;Provider&amp;quot; type=&amp;quot;ProviderImpl&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;object id=&amp;quot;Consumer&amp;quot; type=&amp;quot;ConsumerImpl&amp;quot;&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;properties name=&amp;quot;Provider&amp;quot; ref=&amp;quot;Provider&amp;quot;/&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;/object&amp;gt;&lt;/p&gt;
&lt;p&gt;A user of the consumer has the option of doing a manual lookup:&lt;/p&gt;
&lt;p&gt;var ctx = ContextRegistry.GetContext();&lt;/p&gt;
&lt;p&gt;var x = (IConsumer)ctx.GetObject(&amp;quot;Consumer&amp;quot;);&lt;/p&gt;
&lt;p&gt;Or putting a config in place to inject the dependencies.&lt;/p&gt;
&lt;p&gt;Also, it depends on your environment, but I don't really care how many objects need to be injected into my classes. This is because my application is a long running web application. I take a small startup hit for the first instantiation but after that it goes away.&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8678461</link><pubDate>Tue, 01 Jul 2008 23:05:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8678461</guid><dc:creator>Arnon Rotem-Gal-Oz</dc:creator><description>&lt;p&gt;I know that the title is meant to get attention but it is still wrong&lt;/p&gt;
&lt;p&gt;You are still doing DI.Even something like dependency = new SomeObject(); o = new MyObject(dependency) uses DI. What you are replacing is the IoC container approach...&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8679089</link><pubDate>Wed, 02 Jul 2008 02:26:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8679089</guid><dc:creator>Daniel Jin</dc:creator><description>&lt;p&gt;If you use a service locator, I think this is a pretty good use of SoC through AOP. Although I am not exactly on board with this being a better alternative to DI with a container.&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8680469</link><pubDate>Wed, 02 Jul 2008 10:10:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8680469</guid><dc:creator>Torkel</dc:creator><description>&lt;p&gt;I am also a little puzzled by your list of problems with Service Locator. &lt;/p&gt;
&lt;p&gt;&amp;quot;My main bug-bear with Service Locator is that it permeates throughout all my code. And most importantly, every object I write must know about the Service Locator in order to be able to fetch its dependencies.&amp;quot;&lt;/p&gt;
&lt;p&gt;This is most definitely not true for the most common or &amp;quot;preferred&amp;quot; way to use IoC containers, that is the IoC container is only used by the infrastructure (HttpModule, ControllerFactory, etc). &lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8681146</link><pubDate>Wed, 02 Jul 2008 14:24:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8681146</guid><dc:creator>simonince</dc:creator><description>&lt;P&gt;Great comments everyone, thanks for the thoughts – and keep them coming. I fully admit I don't have all the answers here - this is just a concept I've thrown out to see what the community thinks, so shout up :-)&lt;/P&gt;
&lt;P&gt;Anyway, I'll try and reply to some of the comments so far;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;Nicholas;&lt;/P&gt;
&lt;P&gt;True that classes that rely on this approach are not isolated from their environment *in compiled form* - although they are in source form (as this is the point of AOP). This works for me though - when they are compiled into a system I don't need my code to be isolated. I guess this isn't the case for framework authors etc though, so is a point worth considering.&lt;/P&gt;
&lt;P&gt;Regarding my comment about an object knowing X must be done before Y - you're spot on. I think I explained this badly! My objection is when some other external component must be explicitly invoked to initialize an object. So I don't generally like this;&lt;/P&gt;
&lt;P&gt;MyObject o = new MyObject();&lt;BR&gt;Configurator.ApplySettings(o);&lt;BR&gt;o.DoSomething();&lt;/P&gt;
&lt;P&gt;... but I do like this;&lt;/P&gt;
&lt;P&gt;MyObject o = new MyObject(myConfigurator);&lt;BR&gt;o.Initialize();&lt;BR&gt;o.DoSomething();&lt;/P&gt;
&lt;P&gt;Interesting comments on delegates; I'll be sure to check out autofac.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;Nate &amp;amp; Casey;&lt;/P&gt;
&lt;P&gt;I hear your concerns about being explicit, but I don't think it is a major issue;&lt;/P&gt;
&lt;P&gt;Firstly, I find that being consistent is more important than being explicit - as long as your application *always* resolves objects by doing X, and your documentation (both in code and in docs) states this (explicitly, I guess!!), your developers and support staff will be comfortable with the approach and know where to find things, and how they hang together. &lt;/P&gt;
&lt;P&gt;Secondly, you can use AOP in an explicit way - just move the [assembly:DependencyResolutionAspect] attribute to be on the property itself, rather than hidden away in AssemblyInfo.cs, and it is pretty clear to the developer that an aspect is applied. I just opted to keep it separate because so many DI people hate attribute-based DI :-)&lt;/P&gt;
&lt;P&gt;Thirdly, and most importantly, surely putting all your object configuration in a config file and relying on a container somewhere to build up your objects (i.e. DI) is failing to be explicit too? I would see Service Locator as the most explicit approach, which is why I referred to "some clever people I know actually positively like this approach"... because they like to be explicit and use Service Locator all the time. Am I missing something here?&lt;/P&gt;
&lt;P&gt;You're right though, Casey, trying to hide stuff would be bad!! I'm not aiming to hide implementation; I just want to simplify code so that the real meat of logic that needs to be built and maintained can be focused on without repetitive plumbing code.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;Nate;&lt;/P&gt;
&lt;P&gt;How do you believe AOP will lead to maintenance problems? I'd be really keen to hear your thoughts here as I believe the opposite; simplifying code and hence maintenance is one of my main drivers! Therefore if I've not seen an issue and you have, shout up :-) &lt;/P&gt;&lt;BR&gt;
&lt;P&gt;Ayende;&lt;/P&gt;
&lt;P&gt;1. Surely this *is* IOC!! Just a different approach?&lt;/P&gt;
&lt;P&gt;4. Personally I agree for 99% of cases. Chances are a big database transaction is going to be your bottleneck (by a factor of thousands of times no doubt), not creating one extra object... but I do speak to many people that are cautious of DI - and I love it, so if at all possible I'd love to convince them to consider it... hence this post :-)&lt;/P&gt;
&lt;P&gt;... so I still exercise a little caution because I don't think it is fair to dismiss people's concerns. There are still overheads involved, no matter how small I think they are. If the container is doing more complex configuration of objects it isn't necessarily just a single "new" operation - actually when resolving a chain of 100 objects that might involve many other calls (e.g, 100 look-ups in a Dictionary, 100 calls to check XML configuration, 50 lock { } blocks, 50 object creations, and who knows what else!). &amp;nbsp;I’m sure you can put me straight on how Windsor works mind!&lt;/P&gt;
&lt;P&gt;Anyway, this doesn't change the fact that I believe this to be a completely justified trade-off... but consider Dependency Resolution – all the above downsides hold true, except that due to the “lazy” way it works, one hundredth of this processing would happen if only one of the 100 dependencies were used! Of course, chances are all the clever optimisations that DI containers use could be applied to this too, to really make it fly. Can that be a bad thing? It is an alternative with all the benefits but adding some pretty standard good practices (i.e. a form of lazy loading) to tune the algorithm.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;Arnon;&lt;/P&gt;
&lt;P&gt;Good point :-) &amp;nbsp; Although I think the terminology Dependency Injection has evolved to refer to more than that, I see what you're saying!&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;Torkel;&lt;/P&gt;
&lt;P&gt;Completely agree - but what you refer to is what I would call DI, not Service Locator. With a classic Service Locator, it is the responsibility of the consuming class to "go find the service", and this is what I was referring to.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;Everyone;&lt;/P&gt;
&lt;P&gt;There seems to be a general consensus that DI can do something with clever object configurations etc that some kind of clever service locator can't. Really? Anyone want to volunteer an example to prove it? I just can’t think of a scenario that this holds true for.&lt;/P&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8681199</link><pubDate>Wed, 02 Jul 2008 15:01:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8681199</guid><dc:creator>Casper Bang</dc:creator><description>&lt;p&gt;@Jason&lt;/p&gt;
&lt;p&gt;Yeah well if you use a platform with build in support for the service provider pattern (java.util.ServiceLoader) the danger of being tied to this service is no bigger the way I see it, than being tied to a given build in type, say Decimal. You can only apply the open-closed principle so far.&lt;/p&gt;
&lt;p&gt;I can follow the reasoning for your preference in changing only annotation content rather than actual code, but you STILL need to make modifications, it's just not in the source itself. But then you loose a lot of the reason why you are using a statically typed language to begin with. I.e. the ability for you to be able to read your code when taking a peek at a file in your SCM-system as well as counter your tools ability of to doing static analysis.&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8682195</link><pubDate>Wed, 02 Jul 2008 23:55:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8682195</guid><dc:creator>simonince</dc:creator><description>&lt;p&gt;logicalmind;&lt;/p&gt;
&lt;p&gt;Your example is pretty much how I would use Spring too. The manual resolution approach that DI frameworks provide as well as the &amp;quot;injection&amp;quot; approach is just Service Locator.&lt;/p&gt;
&lt;p&gt;I think I'm going to have to quit with whinging about my comment number [2] (&amp;quot;when using property injection you generally need to mark your dependencies as public&amp;quot;) and admit it isn't really a significant problem... I already pointed out that constructor injection gets around this. I guess I'm just curious as to whether there is an opportunity to use some kind of DI/locator logic to wire up private implementations (i.e. swapping in/out strategies)... but this opens a whole new can of worms.&lt;/p&gt;
&lt;p&gt;Either way, you're spot on - my concern is the public nature of the property (which is defined by an interface) not the class/implementation, as you rightly confirm, but this can be avoided.&lt;/p&gt;
&lt;p&gt;Hope that makes sense!&lt;/p&gt;
&lt;p&gt;Casper;&lt;/p&gt;
&lt;p&gt;You just reminded me of something many people don't know exists in .NET; The IServiceProvider interface - &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/system.iserviceprovider"&gt;http://msdn.microsoft.com/en-us/library/system.iserviceprovider&lt;/a&gt;(VS.80).aspx&lt;/p&gt;
&lt;p&gt;Very basic though :-(&lt;/p&gt;
&lt;p&gt;Cheers everyone! Keep 'em coming, and shout up if I'm talking rubbish :-)&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8682269</link><pubDate>Thu, 03 Jul 2008 00:36:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8682269</guid><dc:creator>Kevin Berridge</dc:creator><description>&lt;p&gt;I tried to write about the complexity that arises from using DI and IoC in a post here: &lt;a rel="nofollow" target="_new" href="http://kevin-berridge.blogspot.com/2008/06/ioc-and-di-complexity.html"&gt;http://kevin-berridge.blogspot.com/2008/06/ioc-and-di-complexity.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I like your ideas about applying AOP to the problem in an attempt to simplify code. &amp;nbsp;Overall I think that many of the draw backs of these types of architectures are still there. &amp;nbsp;And in some ways the &amp;quot;wiring&amp;quot; is even more magical, which does make it harder to understand how it works.&lt;/p&gt;</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8688494</link><pubDate>Fri, 04 Jul 2008 13:09:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8688494</guid><dc:creator>Miguel Madero</dc:creator><description>&lt;p&gt;Simon, &lt;/p&gt;
&lt;p&gt;I'm not sure about how PostShar did this, but I thought it could help eliminate reflection doing that stuff at runtime. &lt;/p&gt;
&lt;p&gt;I tought Laos did some IL magic and somehow compiled the instructions to statically refer to the real stuff instead of goind to reflection.&lt;/p&gt;
&lt;p&gt;Mmm now that I write, altough it sounds possible, dont sound real... Anyway, I wanted to post this. &lt;/p&gt;
&lt;p&gt;I saw Gael read your post and didnt said anything about that.&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8688577</link><pubDate>Fri, 04 Jul 2008 13:24:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8688577</guid><dc:creator>simonince</dc:creator><description>&lt;p&gt;Miguel; &lt;/p&gt;
&lt;p&gt;I agree - it would be great to avoid reflection, and I suspect there are ways this could be done. In fact, I have a nagging feeling that lamdas might help here... but I haven't had time to prove it to myself.&lt;/p&gt;
&lt;p&gt;If you have a look at some code that has had aspects weaved in by PostSharp you should see the use of the methodof() statement. I'm curious why this can't just be hard coded as &amp;quot;MyMethodName&amp;quot; for example, if you don't need detailed runtime reflection information on the caller. I guess it would reduce the flexibility of the framework though.&lt;/p&gt;
&lt;p&gt;If there's a good explanation out there Gael / anyone feel free link to it here...&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8688929</link><pubDate>Fri, 04 Jul 2008 15:12:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8688929</guid><dc:creator>Gael Fraiteur</dc:creator><description>&lt;p&gt;I did post some comment, but it got lost.&lt;/p&gt;
&lt;p&gt;Anyway.&lt;/p&gt;
&lt;p&gt;I don't see in the code where you use reflection, so hard to say how to not use it. &lt;/p&gt;
&lt;p&gt;Gael&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8689496</link><pubDate>Fri, 04 Jul 2008 17:38:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8689496</guid><dc:creator>Miguel Madero</dc:creator><description>&lt;p&gt;There's obviously less reflection, because we wont have the class inspecting all properties, constructor, etc looking for Attributes to do something, but there's still a lot of reflection involved on setting a methods values, dynamically invoking them when needed or getting their return type. All this is using reflecting? or does it get somehow optimized on IL generation? It would still be less reflection than using a DIfx. &lt;/p&gt;
&lt;p&gt;I'm worried about that, specially since reflection is a big hit in the .NET Compact Framework space, and was thinking AOP could be of great help in reducing the amount of reflection needed (once PostSharp supports the CF). &lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8689620</link><pubDate>Fri, 04 Jul 2008 18:10:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8689620</guid><dc:creator>Gael Fraiteur</dc:creator><description>&lt;p&gt;Reflection is not evil, because PostSharp is &amp;quot;just&amp;quot; a bigger reflection engine (with the ability to have random write access to it).&lt;/p&gt;
&lt;p&gt;What is evil is runtime reflection.&lt;/p&gt;
&lt;p&gt;There are many things we can do at compile-time (inside CompileTimeInitialize). We could inspect custom attributes and types there. But anyway the strength (and actually raison d'etre) of the IoC container is the ability to change bindings at runtime. So we cannot ask PostSharp to resolve dependencies at compile-time, it would not make sense. But we could already provide some analysis work.&lt;/p&gt;
&lt;p&gt;PostSharp for CF will not allow user code to be executed at compile time, so it fundamentally limits the set of features. There may be improvements in the future if there is a &amp;quot;market&amp;quot; for this.&lt;/p&gt;
&lt;p&gt;-Gael&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8690080</link><pubDate>Fri, 04 Jul 2008 20:05:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8690080</guid><dc:creator>simonince</dc:creator><description>&lt;p&gt;@ Gael &amp;amp; Miguel,&lt;/p&gt;
&lt;p&gt;I was just typing a reply, and noticed something; I was referring to the reflection PostSharp uses in generated code - i.e. the methodof() operator...&lt;/p&gt;
&lt;p&gt;... but having just looked at my compiled example to get the precise details I noticed it isn't using this at... in which case, I guess it was one of the other aspect types that I noticed this in while playing with PostSharp? Interesting as this would mean I need to retract the comment in my conclusion! &lt;/p&gt;
&lt;p&gt;Can you shed any light on my misunderstanding Gael?&lt;/p&gt;
&lt;p&gt;If we're not using reflection here I'm a very happy bunny :-)&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8692754</link><pubDate>Sat, 05 Jul 2008 09:50:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8692754</guid><dc:creator>Gael Fraiteur</dc:creator><description>&lt;p&gt;PostSharp does not need runtime reflection. For most aspects, it gives the reflection element of the aspect target, but it is only for aspect code. If the aspect does not use this information, it is probable that future versions will not provide it.&lt;/p&gt;
&lt;p&gt;The OnMethodInvocationAspect does not provide explicitely the MethodInfo, because it provides a Delegate, and it is pretty easy to get the MethodInfo from the Delegate.&lt;/p&gt;
&lt;p&gt;Unfortunately, MS implementation of DynamicInvoke is pretty ugly (i.e. ineffective), because it uses reflection behind. I would be better to have to CLR generate this method dynamically, at it does for other delegate methods, but maybe it has not been identified as a key use case by the CLR team.&lt;/p&gt;
&lt;p&gt;Anyway, it is probable that future versions of PostSharp will use a more effective than DynamicInvoke. PostSharp could indeed generate the equivalent of this method, but in MSIL, so without reflection. It would be pretty faster... and compatible with Compact Framework and Silverlight.&lt;/p&gt;
&lt;p&gt;-Gael&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8693280</link><pubDate>Sat, 05 Jul 2008 15:39:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8693280</guid><dc:creator>simonince</dc:creator><description>&lt;p&gt;Great - thanks for clearing that up Gael. I'll edit the post above!&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8695287</link><pubDate>Sun, 06 Jul 2008 02:11:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8695287</guid><dc:creator>Miguel Madero</dc:creator><description>&lt;p&gt;Gael, &lt;/p&gt;
&lt;p&gt;Does PostSharp 1.1 Beta 1 already has support for SL and CF? &lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8696856</link><pubDate>Sun, 06 Jul 2008 17:36:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8696856</guid><dc:creator>Gael Fraiteur</dc:creator><description>&lt;p&gt;Actually yes, but it does not work well enough, so some heavy redesign is required. 1.1 is absolutely not supported yet.&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8698278</link><pubDate>Sun, 06 Jul 2008 23:29:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8698278</guid><dc:creator>Miguel Madero</dc:creator><description>&lt;p&gt;I know its beta, but probably I'll give it a try in the following weeks. I want to expand the concepts presented in this post to the CF. &lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description></item><item><title>The “Service Interface” Pattern</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8894331</link><pubDate>Mon, 25 Aug 2008 20:11:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8894331</guid><dc:creator>Simon Ince's Blog</dc:creator><description>&lt;p&gt;I am constantly surprised when speaking with people how few have heard of or use the “Service Interface”&lt;/p&gt;
</description></item><item><title>re: Dependency Injection is Dead!</title><link>http://blogs.msdn.com/simonince/archive/2008/06/30/dependency-injection-is-dead.aspx#8894805</link><pubDate>Mon, 25 Aug 2008 22:22:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8894805</guid><dc:creator>Gael Fraiteur</dc:creator><description>&lt;p&gt;CF support has been released, btw.&lt;/p&gt;</description></item></channel></rss>