Parts 1 to 3 of this series of articles outlined a series of tests we will be running on various dependency injection frameworks. Part 3 looked at how we would run these tests in Spring for Java using XML configuration.
This article will very briefly look at the same tests being run in Spring.Net.
The full code for this example is available. We have already seen the Movie, MovieLister, SimpleMovieFinder, ColonDelimitedMovieFinder, and ComplexMovieFinder .Net classes. These are pretty much identical to their Java equivalents. In fact the only significant difference is in the ColonDelimitedMovieFinder class, where parsing the Movies.txt file is a little more clunky in .Net than in Java.
Note that these classes will be used for the remainder of the .Net examples in this series of articles.
The Factory Class, Configuration and the Main Client Class
The factory class is also pretty much identical to its Java equivalent. The only real differences are syntactical: in .Net objects are called ‘objects’ not ‘beans’. We can inject the container in .Net in exactly the same way as we do in Java, and retrieve all objects from it of a given type in exactly the same way.
Similarly the XML configuration in .Net is the same as its Java version, and the client code that uses it is also much the same as in Java. I’m not going to go through any of this as it works exactly as for Spring for Java as described in part 3 of this series.
Comments on Spring.Net
Spring.Net is really just a straight port of Spring for Java into C#. As a result the comments made in part 3 of this series on Spring for Java all apply again here: Spring.Net is a good UI framework but again suffers from having configuration in XML. Additionally, in Spring.Net there aren’t the alternatives to using XML that there are in Spring Java.
I’ve ported my examples into Spring.Net to show that it can pass all the tests, and to give us the basic classes (Movie etc.) that we will need to run the tests in the other .Net DI frameworks that we will be examining.