Mercurial > pub > ImplabNet
diff 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 |
line wrap: on
line diff
--- a/Implab.ServiceHost/Unity/ContainerBuilder.cs Fri May 04 18:12:42 2018 +0300 +++ b/Implab.ServiceHost/Unity/ContainerBuilder.cs Fri May 25 19:15:26 2018 +0300 @@ -1,8 +1,12 @@ using System; +using System.IO; using System.Reflection; +using Implab.Diagnostics; using Unity; namespace Implab.ServiceHost.Unity { + using static Trace<ContainerBuilder>; + public class ContainerBuilder { readonly TypeResolver m_resolver; @@ -11,6 +15,8 @@ readonly ContainerConfigurationSchema m_schema; + Uri m_location; + public IUnityContainer Container { get { return m_container; @@ -97,13 +103,39 @@ } + /// <summary> + /// Includes the confguration. Creates a new <see cref="ContainerBuilder"/>, + /// and loads the configuration to it. The created builder will share the + /// container and will have its own isolated type resolver. + /// </summary> + /// <param name="file">A path to configuration relative to the current configuration.</param> public void Include(string file) { var includeContext = new ContainerBuilder(m_container, m_schema); - includeContext.LoadConfig(file); + + if (m_location != null) { + var uri = new Uri(m_location, file); + includeContext.LoadConfig(uri); + } else { + includeContext.LoadConfig(file); + } } + /// <summary> + /// Loads a configuration from the specified local file. + /// </summary> + /// <param name="file">The path to the configuration file.</param> public void LoadConfig(string file) { - var config = m_schema.LoadFile(file); + Safe.ArgumentNotEmpty(file, nameof(file)); + + LoadConfig(new Uri(Path.GetFullPath(file))); + } + + public void LoadConfig(Uri location) { + Safe.ArgumentNotNull(location, nameof(location)); + + m_location = location; + + var config = m_schema.LoadConfig(location.ToString()); config.Visit(this); }