diff --git a/Implab.Playground/Program.cs b/Implab.Playground/Program.cs --- a/Implab.Playground/Program.cs +++ b/Implab.Playground/Program.cs @@ -89,6 +89,17 @@ namespace Implab.Playground { public class Program { static void Main(string[] args) { + var u1 = new Uri("/some/one"); + + Console.WriteLine($"{u1.IsAbsoluteUri}: {u1}"); + + var u2 = new Uri(u1, "../../two"); + + Console.WriteLine($"{u2.IsAbsoluteUri}: {u2}"); + + } + + static void Main2(string[] args) { var listener = new SimpleTraceListener(Console.Out); var source = Trace.TraceSource; source.Switch.Level = SourceLevels.All; diff --git a/Implab.ServiceHost/Unity/ContainerBuilder.cs b/Implab.ServiceHost/Unity/ContainerBuilder.cs --- a/Implab.ServiceHost/Unity/ContainerBuilder.cs +++ b/Implab.ServiceHost/Unity/ContainerBuilder.cs @@ -1,8 +1,12 @@ using System; +using System.IO; using System.Reflection; +using Implab.Diagnostics; using Unity; namespace Implab.ServiceHost.Unity { + using static Trace; + public class ContainerBuilder { readonly TypeResolver m_resolver; @@ -11,6 +15,8 @@ namespace Implab.ServiceHost.Unity { readonly ContainerConfigurationSchema m_schema; + Uri m_location; + public IUnityContainer Container { get { return m_container; @@ -97,13 +103,39 @@ namespace Implab.ServiceHost.Unity { } + /// + /// Includes the confguration. Creates a new , + /// and loads the configuration to it. The created builder will share the + /// container and will have its own isolated type resolver. + /// + /// A path to configuration relative to the current configuration. 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); + } } + /// + /// Loads a configuration from the specified local file. + /// + /// The path to the configuration file. 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); } diff --git a/Implab.ServiceHost/Unity/ContainerConfigurationSchema.cs b/Implab.ServiceHost/Unity/ContainerConfigurationSchema.cs --- a/Implab.ServiceHost/Unity/ContainerConfigurationSchema.cs +++ b/Implab.ServiceHost/Unity/ContainerConfigurationSchema.cs @@ -45,8 +45,8 @@ namespace Implab.ServiceHost.Unity { RegisterContainerElement(typeof(T), name); } - public ContainerElement LoadFile(string file) { - using (var reader = XmlReader.Create(file)) { + public ContainerElement LoadConfig(string uri) { + using (var reader = XmlReader.Create(uri)) { return (ContainerElement)Serializer.Deserialize(reader); } } diff --git a/Implab.ServiceHost/Unity/RegistrationBuilder.cs b/Implab.ServiceHost/Unity/RegistrationBuilder.cs --- a/Implab.ServiceHost/Unity/RegistrationBuilder.cs +++ b/Implab.ServiceHost/Unity/RegistrationBuilder.cs @@ -23,21 +23,5 @@ namespace Implab.ServiceHost.Unity { protected RegistrationBuilder(Type registrationType) { RegistrationType = registrationType; } - - internal void Visit(SingletonLifetimeElement simgletonLifetime) { - Lifetime = new SingletonLifetimeManager(); - } - - internal void Visit(ContainerLifetimeElement containerLifetime) { - Lifetime = new ContainerControlledLifetimeManager(); - } - - internal void Visit(HierarchicalLifetimeElement hierarchicalLifetime) { - Lifetime = new HierarchicalLifetimeManager(); - } - - internal void Visist(ContextLifetimeElement contextLifetime) { - Lifetime = new PerResolveLifetimeManager(); - } } } \ No newline at end of file diff --git a/Implab/Diagnostics/Trace.cs b/Implab/Diagnostics/Trace.cs --- a/Implab/Diagnostics/Trace.cs +++ b/Implab/Diagnostics/Trace.cs @@ -46,6 +46,16 @@ namespace Implab.Diagnostics { } /// + /// Writes a debug message. + /// + /// Format. + /// Arguments. + [Conditional("DEBUG")] + public static void Debug(string format, params object[] arguments) { + + } + + /// /// Writes an informational message. /// /// Format. @@ -60,17 +70,19 @@ namespace Implab.Diagnostics { /// /// Format. /// Arguments. - [Conditional("TRACE")] public static void Warn(string format, params object[] arguments) { TraceSource.TraceEvent(TraceEventType.Warning, 0, format, arguments); } - [Conditional("TRACE")] + /// + /// Writes a error message. + /// + /// Format. + /// Arguments. public static void Error(string format, params object[] arguments) { TraceSource.TraceEvent(TraceEventType.Error, 0, format, arguments); } - [Conditional("TRACE")] public static void Error(Exception err) { TraceSource.TraceData(TraceEventType.Error, 0, err); }