IoC containers finally make sense

by Matt 26. March 2008 11:27

I think I've just had a small epiphany. I've never really grokked the need for Inversion of Control containers, like Castle Windsor, StructureMap or Unity. They've always seemed like overkill. And of course, the reason I've felt like this is that they have been overkill - for the projects where I would have used them.

It's just another case of the right tool for the right job.

Most of the projects I've used have been loosely coupled by default, and while I've used dependency injection, it's never been too many layers deep, so setting up the dependencies has never crossed boundaries they shouldn't have crossed. Sometimes I've put them in config, and a container would definitely have saved me some work here, but not too much. I've always made do with a poor man's solution.

This snippet of code (from an msdn article) showed me how, working on different code, dependency injection would have led me too far down the plug hole:

// Somewhere in UI Layer 
InvoiceSubmissionPresenter presenter = new InvoiceSubmissionPresenter( 
  new InvoiceService( 
    new AuthorizationService(), 
    new InvoiceValidator(), 
    new InvoiceRepository())); 

It was always this wiring up of the dependencies that bothered me, but I was never far enough aware from the deepest layer for it to be properly wrong. Fixing this is exactly what the IoC abstraction is good at. That you get goodies such as lifetime management (per thread, singletons, etc), auto-wiring of dependencies and dynamically generated decorators is just icing on the cake.

Now it's just a case of figuring out which one to use.

Tags:

Comments (19) -

best suv 2010
best suv 2010
7/20/2011 10:30:04 PM #

Fantastic task I like your type! Would really like to right here your feedback on my website! I am also seeking for someone to help you me make websites!

Reply

best hybrid cars
best hybrid cars
7/22/2011 4:19:45 AM #

it ti permette di orientarti con semplicità nel pulviscolare niverso di Moncler.Troverai le indicazioni per lo spaccio o negozio Moncler più vicino a casa tua felpe moncler, pantaloni e abbigliamento sportivo.

Reply

iphone os 4
iphone os 4
7/23/2011 7:50:10 PM #

Is it ok if I quote your article in my monthly newsletter? I would think this article suits my topic perfectly. Well ya, thanks for posting this article.

Reply

Philix
Philix United States
11/23/2015 3:42:55 AM #

Good Site.

Reply

Loren Benward
Loren Benward United States
1/15/2016 4:58:50 AM #

getting laid AWSOME

Reply

Rosario Carello
Rosario Carello United States
1/15/2016 5:00:12 AM #

Well good for you! I have a lot but one I just thought of was when you lick a crease of paper so that it'll rip in a straight line and it actually tears in a frayed straight line rather than rips awkwardly. I love that bleachy taste and that bleachy satisfaction.

Reply

Palmer Rinck
Palmer Rinck United States
1/15/2016 7:49:11 AM #

Thaaaat IS awesome! lol hehe

Reply

Gia Agramonte
Gia Agramonte United States
1/15/2016 8:32:34 AM #

AWESOME!Can't wait for that, will be something to want to accomplish day by day, to do something AWESOME!

Reply

Marquis Sumrell
Marquis Sumrell United States
7/21/2016 4:11:12 PM #

Favourable day I am therefore grateful I found out your weblog, I really uncovered yourself by way of incident, while I was studying on Aol for a little something else

Reply

Chad Cassem
Chad Cassem United States
8/25/2016 4:17:59 AM #

Construction industry is adapting the latest technology. Smart house buildersdesigners are having nice niche

Reply

CLEVIEL 高濃度透明質酸
CLEVIEL 高濃度透明質酸 United States
10/9/2018 6:30:16 PM #

它讓神經原在常規的緊張鍛煉中進行共振燃燒,由此帶來健身運動所無法達到的效果。Ion Magnum複雜的振動波是基于於二十多年對神經原燃燒信號的研究手工製作的。 設備製造者的臨床研究結果顯示,30分鐘的治療相當於在健身房10個小時的運動,可以燃燒高達5000卡路里的熱量。其他臨床研究顯示肌肉生成的速度以及脂肪(表面脂肪以及深部脂肪)减少的速度相應都比運動的效果更好。對於Ion Magnum沒有進行理療的部位,甚至會有抗衰老防氧化的效果。 有受試者治療一次之後同一個部位减掉了3-4英寸(不像其他减肥治療中宣稱的那樣,一次治療减掉了5英寸,但那是全身20多個部位加起來减掉的尺寸)。同時,它還可以减掉脖子和下巴的脂肪,讓你的雙下巴消失 . 每次治療需要25分鐘。治療前後的效果非常明顯,而且會持續1-2天。要想達到更好的效果,最好接受1-2個小時的治療。

Reply

植物幹細胞活肌去角質啫喱The Body Shop®  从 The Body Shop 购买 植物幹細胞活肌去角質啫喱 : 蕴含雪绒花、海滨刺芹及海茴香的纯净养份,水嫩的啫喱质地能温和去除肌肤老化角质及污染物,令肌肤变得平滑,同时净化肌肤,为随后吸收后续的补湿产品作好准备,让肌肤回复健康活力!      

Reply

桿菌
桿菌 United States
10/11/2018 3:50:31 PM #

濃密質地、潤澤守護肌膚每一吋使肌膚湧現強韌彈力,實現煥新般的容顏的精華液

Reply

醫學美容 飛針 cosmetic.wiki
醫學美容 飛針 cosmetic.wiki United States
10/18/2018 10:58:52 AM #

LORA LISA 全效保濕嫩白乳液 - 羅娜麗莎國際有限公司Lora Lisa International Limited  LORA LISA 全效保濕嫩白乳液 - 羅娜麗莎國際有限公司Lora Lisa International Limited      

Reply

醫學美容 化妝 cosmetic.wiki
醫學美容 化妝 cosmetic.wiki United States
10/19/2018 4:41:39 AM #

ARWIN 雅聞 【芳香精油】罩杯型立體口罩的商品介紹   ARWIN 雅聞,芳香精油,罩杯型立體口罩       

Reply

醫學美容 Dysport 小V臉
醫學美容 Dysport 小V臉 United States
10/21/2018 5:52:01 PM #

FineScan 會在肌膚上製造數以千計的細小深入傷口,即所謂的顯微加熱區(microthermal zone),但要確保每次治療時皆有部份組織不受能量影響,於是,每一個顯微加熱區的作用雖然強烈而明顯,但周圍都包覆著正常且結構完整的皮膚組織,使傷口能在短時間內癒合,並替換之前有缺陷的受損組織。Finescan不僅可讓表皮新生,更可促進深層膠原再生,從內而外徹底喚醒細胞,瞬時找回年輕時的肌膚狀態。憑藉最新的雙軸技術,FINESCAN 6可治療 - 面部 - 頸部 - 暗瘡凹凸洞 - 增生性疤痕

Reply

來自瑞士的Teosyal®透明質酸,是由世界第三大以透明質酸為基礎的TEOXANE藥廠研發。Teosyal ®Redensity II® 是專門為眼部肌膚而設計的透明質酸。屬於半鏈結透明質酸的Redensity II® ,輕微吸濕力可減少水腫。 半鏈結透明質酸的柔軟度較高,於注射之後不會產主粒狀問題。可撫平中度皺紋,主要用於淚溝、額紋、手部填充、木偶紋、豐唇、耳珠、太陽穴、人中、面頰填充、虎紋

Reply

Liverpool’s schedule saw them sign off with a trip to West Brom. The day was significant for Danny Ings, who had made an astonishing recovery from a torn anterior cruciate ligament to play a part. Danny Ings relishing being back in Liverpool fold and determined to prove people wrong all over again

Reply

fortnite download windows 10
fortnite download windows 10 United States
3/15/2019 12:47:08 AM #

I cherished up to you'll obtain carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get got an edginess over that you wish be turning in the following. ill for sure come more previously again as precisely the similar just about very ceaselessly inside case you protect this hike.

Reply

Add comment

biuquote
  • Comment
  • Preview
Loading

Rel=Me

Month List

RecentComments

Comment RSS