开发者

IoC from start to finish

开发者 https://www.devze.com 2022-12-27 15:49 出处:网络
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 co开发者_高级运维ntainers.I\'ve read several blogs tod

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 co开发者_高级运维ntainers. 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?


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

  • Martin Fowler's "Inversion of Control Containers and the Dependency Injection pattern"
  • Miško Hevery's "Dependency Injection Myth: Reference Passing"

(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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号