Mercurial > pub > ImplabNet
comparison Implab.Playground/Program.cs @ 277:963b17c275be v3
Refactoring
Added <array> element to injection parameters
Working on registrations of factories
author | cin |
---|---|
date | Sat, 28 Apr 2018 18:48:09 +0300 |
parents | 22629bf26121 |
children | 6691aff01de1 |
comparison
equal
deleted
inserted
replaced
276:b4e0f81c7425 | 277:963b17c275be |
---|---|
1 using System; | 1 using System; |
2 using System.Collections.Generic; | |
2 using System.Diagnostics; | 3 using System.Diagnostics; |
3 using System.Linq; | 4 using System.Linq; |
4 using Implab.Diagnostics; | 5 using Implab.Diagnostics; |
5 using Implab.ServiceHost.Unity; | 6 using Implab.ServiceHost.Unity; |
6 using Implab.Xml; | 7 using Implab.Xml; |
20 | 21 |
21 public int IntValue { get; set; } | 22 public int IntValue { get; set; } |
22 | 23 |
23 public string StringValue { get; set; } | 24 public string StringValue { get; set; } |
24 | 25 |
26 public void AddRange(Foo[] items) { | |
27 Console.WriteLine($"AddRange: Foo[]"); | |
28 } | |
29 | |
25 } | 30 } |
26 | 31 |
27 public interface IContainer<T> { | 32 public interface IContainer<T> { |
28 T Instance { get; set; } | 33 T Instance { get; set; } |
29 } | 34 } |
40 public T Instance { get; set; } | 45 public T Instance { get; set; } |
41 | 46 |
42 public void SetInstance(T value) { | 47 public void SetInstance(T value) { |
43 Instance = value; | 48 Instance = value; |
44 } | 49 } |
50 | |
51 public void AddRange(List<T> items) { | |
52 Console.WriteLine($"AddRange: {typeof(List<T>)}"); | |
53 } | |
54 | |
55 public void AddRange(T[] items) { | |
56 Console.WriteLine($"AddRange: T[] ofType {typeof(T[])}"); | |
57 } | |
45 } | 58 } |
46 | 59 |
47 public class Program { | 60 public class Program { |
48 | 61 |
49 static void Main(string[] args) { | 62 static void Main(string[] args) { |
63 var listener = new SimpleTraceListener(Console.Out); | |
64 var source = Trace<TypeResolver>.TraceSource; | |
65 source.Switch.Level = SourceLevels.All; | |
66 source.Listeners.Add(listener); | |
67 | |
50 var stopwatch = new Stopwatch(); | 68 var stopwatch = new Stopwatch(); |
51 stopwatch.Start(); | 69 stopwatch.Start(); |
52 | 70 |
53 var ctx = new ContainerBuilder(); | 71 var ctx = new ContainerBuilder(); |
54 | 72 |
55 Console.WriteLine($"Created: {stopwatch.ElapsedMilliseconds}"); | 73 Console.WriteLine($"Created: {stopwatch.ElapsedMilliseconds}"); |
56 | 74 stopwatch.Restart(); |
75 | |
57 ctx.LoadConfig("data/sample.xml"); | 76 ctx.LoadConfig("data/sample.xml"); |
58 | 77 |
59 Console.WriteLine($"Loaded: {stopwatch.ElapsedMilliseconds}"); | 78 Console.WriteLine($"Loaded: {stopwatch.ElapsedMilliseconds}"); |
60 | 79 |
61 var container = ctx.Container; | 80 var container = ctx.Container; |
62 | 81 |
63 | 82 stopwatch.Restart(); |
64 | |
65 var instace1 = container.Resolve<IContainer<string>>(); | 83 var instace1 = container.Resolve<IContainer<string>>(); |
66 Console.WriteLine($"Resolved1: {stopwatch.ElapsedMilliseconds}"); | 84 Console.WriteLine($"Resolved1: {stopwatch.ElapsedMilliseconds}"); |
85 | |
86 stopwatch.Restart(); | |
67 var instace2 = container.Resolve<IContainer<Foo>>(); | 87 var instace2 = container.Resolve<IContainer<Foo>>(); |
68 | |
69 Console.WriteLine($"Resolved2: {stopwatch.ElapsedMilliseconds}"); | 88 Console.WriteLine($"Resolved2: {stopwatch.ElapsedMilliseconds}"); |
70 | 89 |
71 DisplayContainerRegistrations(container); | 90 DisplayContainerRegistrations(container); |
72 } | 91 } |
73 | 92 |