3

I'm quite sure that IoC is the way to go for my application. There are a ton of articles and even questions here on SO that discuss the different containers. I've read several blogs today with partial examples. I am personally leaning towards starting with the CommonServiceLocator and Unity as two way to solve the same problem -- I just need a bunch of assemblies to get data from a database, which I assume is what needs to be injected everywhere.

I've yet to find any sites that really take a problem from beginning to end, with concrete code examples. For example, I've yet to find one that discusses an IServiceLocator and how to actually register it (or do whatever is required to make it known).

What are your favorite posts / articles / SO questions that can take a noob from start to finish with the implementation?

alexandrul
  • 12,856
  • 13
  • 72
  • 99
Dave
  • 14,618
  • 13
  • 91
  • 145
  • 3
    you most likely don't need or want an IServiceLocator – Mauricio Scheffer Apr 16 '10 at 12:35
  • I won't be able to anyway because I haven't yet figured it out. ;) Unity and MEF are the ones I'm playing with now in parallel. Nothing is a silver bullet, but I wasn't exactly expecting that anyway. I'm focusing on MEF the most right now, though. – Dave Apr 18 '10 at 06:01
  • 2
    MEF is not exactly a IoC container. If you want pluggability - use MEF; if you want modularity, use actual IoC container, like Windsor of Autofac – Krzysztof Kozmic Apr 18 '10 at 16:58
  • 2
    And you **certainly** don't want to use service locator – Krzysztof Kozmic Apr 18 '10 at 16:59
  • hmmm... I've always considered pluggability to be basically the same as modularity. Don't both imply that you'll be resolving interfaces and that you can control what you're instantiating? – Dave Apr 19 '10 at 02:44
  • 2
    @Dave: not quite the same thing. MEF is more geared towards runtime discovery of potentially unknown modules/plugins. IoC containers are designed more with static injection in mind. – Mauricio Scheffer Apr 28 '10 at 01:39
  • [NINJECT IT!](http://ninject.org) – Justin May 06 '10 at 08:54
  • @Justin: I briefly looked at Ninject, but haven't tried it yet. The fluidity of programming with it is a hard concept for me to grasp at the moment. :) – Dave May 06 '10 at 14:25

2 Answers2

3

If you haven't already read them, I recommend:

(I also recommend reading ploeh blog - Mark writes about DI as well as or better than anyone).

Neither provides an end-to-end application example, but together they provide a solid outline.

Fowler's article is critical to understanding the different types of dependency injection (and you may have already read it, based on your question), but I really had to read Hevery's article before I grokked how I'd use DI in the real world. (And you should read more of Hevery's stuff or Mark Seemann's "Service Locator is an Anti-Pattern", if only to understand why you shouldn't use service locator!)

Finally, one thing that I don't often see stated explicitly: your top-level applications are the only things that should reference your dependency injection framework classes.

Community
  • 1
  • 1
Jeff Sternal
  • 47,787
  • 8
  • 93
  • 120
0

If you're still interested in using Unity, then the following screencast is worth the download - Unity IoC Fundamentals. While it does have real world examples at the end, unfortunately he absolutely flies through them - though there are links to blog posts further explaining the examples which you could go through at your own pace if interested.

Bermo
  • 4,921
  • 1
  • 28
  • 31