// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using Spring.Context; using Spring.Context.Support; namespace E { public interface I { string WhoAmI(); } public class X : I { private static int totno = 0; private int no; private I o; public X(I o) { this.o = o; totno++; no = totno; } public string WhoAmI() { return "I am X " + no + "/" + totno + " with: " + o.WhoAmI(); } } public class Y : I { private static int totno = 0; private int no; public Y() { totno++; no = totno; } public string WhoAmI() { return "I am Y " + no + "/" + totno; } } public class Program { public static void Main(string[] args) { IApplicationContext ctx = ContextRegistry.GetContext(); for(int i = 0; i < 5; i++) { I o = (I)ctx.GetObject ("X"); Console.WriteLine(o.WhoAmI()); } } } }