This post originated from an RSS feed registered with .NET Buzz
by Udi Dahan.
Original Post: Spring.net gets method injection!
Feed Title: Udi Dahan - The Software Simplist
Feed URL: http://feeds.feedburner.com/UdiDahan-TheSoftwareSimplist
Feed Description: I am a software simplist. I make this beast of architecting, analysing, designing, developing, testing, managing, deploying software systems simple.
This blog is about how I do it.
You might remember my previous post on Dependency Injection Woes where I bemoaned the issue of string naming as well as the lack of method injection. Well, it turns out that the latest version of Spring.net has just added method injection.
I just wanted to mention one not-so-small issue I have with method injection - it's testability.
When using the IObjectBuilder I described in the previous post, when I wanted to test the class that needed to create a new instance of another object at runtime (it's code looking like this: "this.builder.Build();"), I could do something like this (using NUnit.Mocks):
DynamicMock builderMock = new DynamicMock(typeof(IBuilder));
DynamicMock otherObjectMock = new DynamicMock(typeof(IOtherObject));
unitUnderTest.builder = builderMock.MockInstance as IBuilder;
And I could embellish properties and such on the created object.
With method injection, in my tests I have to subclass the unit under test and override the method. While both styles work, and I think I like the way the production code comes out with method injection better, the added weight for testing is a drag.
The law of conservation of energy will apparently always apply.