Tom Whitner
10-20-2004, 03:15 PM
Most people should be familiar with Fowler's article regaring this comparison. If not, please look at http://martinfowler.com/articles/injection.html. In his article, Fowler presents the MovieLister/MovieFinder example that Spring.NET implemented as its example. As I examined this example, I was bothered by the following few lines of code.
IApplicationContext ctx = ConfigurationSettings.GetConfig("objects") as IApplicationContext;
MovieLister lister = (MovieLister) ctx.GetObject("MyMovieLister");
Movie[] movies = lister.MoviesDirectedBy("Roberto Benigni");
As I look at this code, I see the use of a Service Locator. My first question is whether that is correct or not. Does the call to ctx.GetObject() qualify as Service Location or not? If so, it seems to me that any Dependency Injection must rely on Service Location to initiate it. I'd like to hear other people oppinion in this.
Thanks,
Tom
IApplicationContext ctx = ConfigurationSettings.GetConfig("objects") as IApplicationContext;
MovieLister lister = (MovieLister) ctx.GetObject("MyMovieLister");
Movie[] movies = lister.MoviesDirectedBy("Roberto Benigni");
As I look at this code, I see the use of a Service Locator. My first question is whether that is correct or not. Does the call to ctx.GetObject() qualify as Service Location or not? If so, it seems to me that any Dependency Injection must rely on Service Location to initiate it. I'd like to hear other people oppinion in this.
Thanks,
Tom