268
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.Text.RegularExpressions;
|
|
4 using Implab.Diagnostics;
|
|
5
|
|
6 namespace Implab.ServiceHost.Unity {
|
|
7 using System.Linq;
|
269
|
8 using System.Reflection;
|
268
|
9 using System.Text;
|
269
|
10 using global::Unity;
|
270
|
11 using Implab.Xml;
|
268
|
12 using static Trace<ConfigurationContext>;
|
|
13
|
|
14 public class ConfigurationContext {
|
|
15
|
270
|
16 readonly TypeResolver m_resolver;
|
|
17
|
|
18
|
268
|
19
|
269
|
20 readonly UnityContainer m_container;
|
270
|
21
|
269
|
22 public ConfigurationContext(UnityContainer container) {
|
|
23 m_container = container ?? new UnityContainer();
|
270
|
24 m_resolver = new TypeResolver();
|
268
|
25 }
|
|
26
|
|
27
|
270
|
28 public Type Resolve(string typeReference) {
|
|
29 return m_resolver.Resolve(TypeReference.Parse(typeReference));
|
268
|
30 }
|
|
31
|
270
|
32 internal void Visit(AbstractRegistration descriptor) {
|
269
|
33
|
|
34 }
|
|
35
|
270
|
36 internal void Visit(NamespaceElement namespaceElement) {
|
|
37 m_resolver.AddNamespace(namespaceElement.Name);
|
|
38 }
|
|
39
|
|
40 internal void Visit(AssemblyElement assemblyElement) {
|
|
41 Assembly.Load(assemblyElement.AssemblyName);
|
|
42 }
|
|
43
|
|
44 internal void Visit(IncludeElement includeElement) {
|
|
45 Include(includeElement.Href);
|
|
46 }
|
|
47
|
269
|
48 public void Include(string file) {
|
270
|
49 var includeContext = new ConfigurationContext(m_container);
|
|
50 includeContext.LoadConfig(file);
|
|
51 }
|
268
|
52
|
270
|
53 public void LoadConfig(string file) {
|
|
54 var config = SerializationHelpers.DeserializeFromFile<ContainerElement>(file);
|
|
55 Visit(config);
|
|
56 }
|
|
57
|
|
58 public void Visit(ContainerElement containerElement) {
|
|
59 foreach (var item in containerElement.Items)
|
|
60 item.Visit(this);
|
268
|
61 }
|
|
62
|
|
63 }
|
|
64 } |