Mercurial > pub > ImplabNet
comparison Implab.ServiceHost/Unity/ContainerBuilder.cs @ 280:f07be402ab02 v3
Added Trace<T>.Debug(...) method for debug messages
Added ContainerBuilde.LoadConfig(Uri) method
author | cin |
---|---|
date | Fri, 25 May 2018 19:15:26 +0300 |
parents | 8714471e8d78 |
children |
comparison
equal
deleted
inserted
replaced
279:8714471e8d78 | 280:f07be402ab02 |
---|---|
1 using System; | 1 using System; |
2 using System.IO; | |
2 using System.Reflection; | 3 using System.Reflection; |
4 using Implab.Diagnostics; | |
3 using Unity; | 5 using Unity; |
4 | 6 |
5 namespace Implab.ServiceHost.Unity { | 7 namespace Implab.ServiceHost.Unity { |
8 using static Trace<ContainerBuilder>; | |
9 | |
6 public class ContainerBuilder { | 10 public class ContainerBuilder { |
7 | 11 |
8 readonly TypeResolver m_resolver; | 12 readonly TypeResolver m_resolver; |
9 | 13 |
10 readonly IUnityContainer m_container; | 14 readonly IUnityContainer m_container; |
11 | 15 |
12 readonly ContainerConfigurationSchema m_schema; | 16 readonly ContainerConfigurationSchema m_schema; |
17 | |
18 Uri m_location; | |
13 | 19 |
14 public IUnityContainer Container { | 20 public IUnityContainer Container { |
15 get { | 21 get { |
16 return m_container; | 22 return m_container; |
17 } | 23 } |
95 | 101 |
96 public void AddAssembly(string assembly) { | 102 public void AddAssembly(string assembly) { |
97 | 103 |
98 } | 104 } |
99 | 105 |
106 /// <summary> | |
107 /// Includes the confguration. Creates a new <see cref="ContainerBuilder"/>, | |
108 /// and loads the configuration to it. The created builder will share the | |
109 /// container and will have its own isolated type resolver. | |
110 /// </summary> | |
111 /// <param name="file">A path to configuration relative to the current configuration.</param> | |
100 public void Include(string file) { | 112 public void Include(string file) { |
101 var includeContext = new ContainerBuilder(m_container, m_schema); | 113 var includeContext = new ContainerBuilder(m_container, m_schema); |
102 includeContext.LoadConfig(file); | 114 |
115 if (m_location != null) { | |
116 var uri = new Uri(m_location, file); | |
117 includeContext.LoadConfig(uri); | |
118 } else { | |
119 includeContext.LoadConfig(file); | |
120 } | |
103 } | 121 } |
104 | 122 |
123 /// <summary> | |
124 /// Loads a configuration from the specified local file. | |
125 /// </summary> | |
126 /// <param name="file">The path to the configuration file.</param> | |
105 public void LoadConfig(string file) { | 127 public void LoadConfig(string file) { |
106 var config = m_schema.LoadFile(file); | 128 Safe.ArgumentNotEmpty(file, nameof(file)); |
129 | |
130 LoadConfig(new Uri(Path.GetFullPath(file))); | |
131 } | |
132 | |
133 public void LoadConfig(Uri location) { | |
134 Safe.ArgumentNotNull(location, nameof(location)); | |
135 | |
136 m_location = location; | |
137 | |
138 var config = m_schema.LoadConfig(location.ToString()); | |
107 config.Visit(this); | 139 config.Visit(this); |
108 } | 140 } |
109 | 141 |
110 } | 142 } |
111 } | 143 } |