StartUp Class – Spring.Net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
namespace MovieFinderTestSpring.Net
    class Program
        static void Main(string[] args)
            // Get one object from the Movie class configured with specific values
            IApplicationContext context = ContextRegistry.GetContext();
            Movie andreiRublev = (Movie)context.GetObject("AndreiRublevMovie");
            Console.WriteLine("TEST 1: Configuration and retrieval of an object with (only) string dependencies");
            Console.WriteLine("Should show one Tarkovsky movie:");
            Console.WriteLine("Spring.Net XML: " + andreiRublev.ToString());
            // Finder injected into Lister by constructor injection.  Only one Lister
            // class here, configured to use two different Finders (SimpleMovieFinder
            // and ColonDelimitedMovie Finder.  Both of the Finders
            // implement the MovieFinder interface of course, and are injected
            // using that.
            Console.WriteLine("TEST 2: Injection of an object into an instance of a class.");
            Console.WriteLine("Should show list of James Cameron movies:");
            MovieLister simpleLister = (MovieLister)context.GetObject("simpleMovieLister");
            Movie[] jamesCameronMovies = simpleLister.MoviesDirectedBy("James Cameron");
            foreach (Movie movie in jamesCameronMovies)
            // Finder injected by setter injection.  See comments above.
            MovieLister colonDelimitedLister = (MovieLister)context.GetObject("colonDelimitedMovieLister");
            Movie[] martinScorseseMovies = colonDelimitedLister.MoviesDirectedBy("Martin Scorsese");
            Console.WriteLine("TEST 3: Injection of a different object into an instance of the same class as used in test 2.");
            Console.WriteLine("Should show list of Martin Scorsese movies:");
            foreach (Movie movie in martinScorseseMovies)
            // Test scope by requesting a second lister of each type: 
            // the singleton scope SimpleMovieLister should return the same object
            // as above, the prototype scope ColonDelimitedMovieLister should
            // return a new object (which will have a different ID).
            Console.WriteLine("TEST 4: Creation of an object with singleton scope (same object retrieved from the container every time requested).");
            Console.WriteLine("Versions of requested objects should be the same:");
            Console.WriteLine("First requested simple lister (singleton) version = " + simpleLister.VersionID);
            MovieLister simpleLister2 = (MovieLister)context.GetObject("simpleMovieLister");
            Console.WriteLine("Second requested simple lister version = " + simpleLister2.VersionID);
            Console.WriteLine("TEST 5: Creation of an object with prototype or transient scope (different (new) object retrieved from the container every time requested).");
            Console.WriteLine("Versions of requested objects should be different:");
            Console.WriteLine("First requested colon delimited lister (prototype) version = " + colonDelimitedLister.VersionID);
            MovieLister colonDelimitedLister2 = (MovieLister)context.GetObject("colonDelimitedMovieLister");
            Console.WriteLine("Second requested colon delimited lister version = " + colonDelimitedLister2.VersionID);
            Console.WriteLine("TESTS 6 AND 7: Use of a factory class and injection of the container to create a dependent object.");
            Console.WriteLine("Should show Tarkovsky movie:");
            // Need an example with more complex construction via a factory method
            MovieLister complexLister = (MovieLister)context.GetObject("complexMovieLister");
            Movie[] tarkovskyMovies = complexLister.MoviesDirectedBy("Andrei Tarkovsky");
            foreach (Movie movie in tarkovskyMovies)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s