comparison Implab.Playground/Program.cs @ 279:8714471e8d78 v3

Container configuration cleanup, RC2
author cin
date Fri, 04 May 2018 18:12:42 +0300
parents 6691aff01de1
children f07be402ab02
comparison
equal deleted inserted replaced
278:6691aff01de1 279:8714471e8d78
92 var listener = new SimpleTraceListener(Console.Out); 92 var listener = new SimpleTraceListener(Console.Out);
93 var source = Trace<TypeResolver>.TraceSource; 93 var source = Trace<TypeResolver>.TraceSource;
94 source.Switch.Level = SourceLevels.All; 94 source.Switch.Level = SourceLevels.All;
95 source.Listeners.Add(listener); 95 source.Listeners.Add(listener);
96 96
97 var resolver = new TypeResolver(); 97 var stopwatch = new Stopwatch();
98 resolver.AddNamespace("System"); 98 stopwatch.Start();
99 resolver.AddNamespace("System.Collections.Generic");
100 resolver.AddNamespace("Implab.Playground");
101 resolver.AddMapping("string", typeof(string));
102 resolver.AddMapping("listOf`1", typeof(List<>));
103 99
104 var spec = TypeReference.Parse("Container{listOf{string}}+Bar{List{string}}"); 100 var container = new UnityContainer();
105 101
106 var t = resolver.Resolve(spec, true); 102 Console.WriteLine($"Created: {stopwatch.ElapsedMilliseconds}");
103 stopwatch.Restart();
104
105 container.LoadXmlConfiguration("data/sample.xml");
107 106
108 Console.WriteLine("{0}", t); 107 Console.WriteLine($"Loaded: {stopwatch.ElapsedMilliseconds}");
109 Console.WriteLine("Spec: {0}", spec); 108
110 Console.WriteLine("IsGenericType: {0}", t.IsGenericType); 109 stopwatch.Restart();
111 Console.WriteLine("IsGenericTypeDefinition: {0}", t.IsGenericTypeDefinition); 110 var instace1 = container.Resolve<IContainer<string>>();
112 Console.WriteLine("ContainsGenericParameters: {0}", t.ContainsGenericParameters); 111 Console.WriteLine($"Resolved1: {stopwatch.ElapsedMilliseconds}");
112
113 stopwatch.Restart();
114 var instace2 = container.Resolve<IContainer<Foo>>();
115 Console.WriteLine($"Resolved2: {stopwatch.ElapsedMilliseconds}");
116
117 DisplayContainerRegistrations(container);
113 } 118 }
114 119
115 static void DisplayContainerRegistrations(IUnityContainer theContainer) { 120 static void DisplayContainerRegistrations(IUnityContainer theContainer) {
116 string regName, regType, mapTo, lifetime; 121 string regName, regType, mapTo, lifetime;
117 Console.WriteLine("Container has {0} Registrations:", 122 Console.WriteLine("Container has {0} Registrations:",