annotate Implab.Playground/Program.cs @ 272:9d1cca834b05 v3

preview version of Unity xml configuration
author cin
date Thu, 26 Apr 2018 03:14:54 +0300
parents d4d437ec4483
children 79110a16cab7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
1 using System;
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
2 using System.Diagnostics;
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
3 using System.Linq;
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
4 using Implab.Diagnostics;
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
5 using Implab.ServiceHost.Unity;
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
6 using Implab.Xml;
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
7 using Unity;
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
8 using Unity.Injection;
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
9 using Unity.Registration;
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
10
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
11 namespace Implab.Playground {
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
12
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
13 public class Foo {
269
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
14
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
15 public class Bar {
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
16
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
17 }
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
18
270
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
19 public string Name { get; set; }
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
20
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
21 public int IntValue { get; set; }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
22
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
23 public string StringValue { get; set; }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
24
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
25 }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
26
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
27 public interface IContainer<T> {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
28 T Instance { get; set; }
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
29 }
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
30
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
31 public class Container<T> : IContainer<T> {
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
32 public Container() {
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
33
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
34 }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
35
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
36 public Container(T instance) {
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
37 Instance = instance;
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
38 }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
39
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
40 public T Instance { get; set; }
270
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
41
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
42 public void SetInstance(T value) {
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
43 Instance = value;
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
44 }
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
45 }
255
b00441e04738 Adde workaround to the behaviour of the logical operations stack in conjuction
cin
parents: 236
diff changeset
46
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
47 public class Program {
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
48
255
b00441e04738 Adde workaround to the behaviour of the logical operations stack in conjuction
cin
parents: 236
diff changeset
49 static void Main(string[] args) {
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
50 var container = new UnityContainer();
255
b00441e04738 Adde workaround to the behaviour of the logical operations stack in conjuction
cin
parents: 236
diff changeset
51
271
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
52 var ctx = new ConfigurationContext(container);
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
53
269
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
54 var conf = SerializationHelpers.DeserializeFromFile<ContainerElement>("data/sample.xml");
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
55
271
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
56 ctx.Visit(conf);
d4d437ec4483 Working on Unity xml configuration
cin
parents: 270
diff changeset
57
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
58 DisplayContainerRegistrations(container);
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
59
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
60 var instace1 = container.Resolve<IContainer<string>>();
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
61 var instace2 = container.Resolve<IContainer<Foo>>();
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
62
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
63 }
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
64
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
65 static void DisplayContainerRegistrations(IUnityContainer theContainer) {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
66 string regName, regType, mapTo, lifetime;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
67 Console.WriteLine("Container has {0} Registrations:",
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
68 theContainer.Registrations.Count());
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
69 foreach (ContainerRegistration item in theContainer.Registrations) {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
70 regType = item.RegisteredType.FullName;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
71 mapTo = item.MappedToType.FullName;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
72 regName = item.Name ?? "[default]";
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
73 lifetime = item.LifetimeManager.LifetimeType.Name;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
74 if (mapTo != regType) {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
75 mapTo = " -> " + mapTo;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
76 } else {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
77 mapTo = string.Empty;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
78 }
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
79 lifetime = lifetime.Substring(0, lifetime.Length - "LifetimeManager".Length);
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
80 Console.WriteLine("+ {0}{1} '{2}' {3}", regType, mapTo, regName, lifetime);
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
81 }
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
82 }
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
83
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
84
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
85 }
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
86 }