# HG changeset patch # User cin # Date 2018-04-25 16:23:35 # Node ID d4d437ec4483e2f9a507c72374c93244bde1ba45 # Parent ade80d94dfb5f48e774c6dabb16645cc617d928a Working on Unity xml configuration diff --git a/Implab.Playground/Program.cs b/Implab.Playground/Program.cs --- a/Implab.Playground/Program.cs +++ b/Implab.Playground/Program.cs @@ -43,8 +43,12 @@ namespace Implab.Playground { static void Main(string[] args) { var container = new UnityContainer(); + var ctx = new ConfigurationContext(container); + var conf = SerializationHelpers.DeserializeFromFile("data/sample.xml"); + ctx.Visit(conf); + Console.WriteLine($"Registrations: {conf.Items.Count}"); } diff --git a/Implab.ServiceHost/Unity/AbstractRegistration.cs b/Implab.ServiceHost/Unity/AbstractRegistration.cs --- a/Implab.ServiceHost/Unity/AbstractRegistration.cs +++ b/Implab.ServiceHost/Unity/AbstractRegistration.cs @@ -15,6 +15,18 @@ namespace Implab.ServiceHost.Unity get; set; } + [XmlElement("signleton", typeof(SimgletonLifetimeElement))] + [XmlElement("context", typeof(ContextLifetimeElement))] + [XmlElement("container", typeof(ContainerLifetimeElement))] + [XmlElement("hierarchy", typeof(HierarchicalLifetimeElement))] + public LifetimeElement Lifetime {get; set;} + + /// + /// A type specification for the service registration, + /// + [XmlAttribute("provides")] + public string ProvidesType { get; set; } + public void Visit(ConfigurationContext context) { context.Visit(this); } diff --git a/Implab.ServiceHost/Unity/ConfigurationSchema.cs b/Implab.ServiceHost/Unity/ConfigurationSchema.cs --- a/Implab.ServiceHost/Unity/ConfigurationSchema.cs +++ b/Implab.ServiceHost/Unity/ConfigurationSchema.cs @@ -38,6 +38,9 @@ namespace Implab.ServiceHost.Unity { var schema = new ConfigurationSchema(); schema.DefineMapping(); + schema.DefineMapping(); + schema.DefineMapping(); + schema.DefineMapping(); return schema; } diff --git a/Implab.ServiceHost/Unity/ContainerElement.cs b/Implab.ServiceHost/Unity/ContainerElement.cs --- a/Implab.ServiceHost/Unity/ContainerElement.cs +++ b/Implab.ServiceHost/Unity/ContainerElement.cs @@ -22,7 +22,10 @@ namespace Implab.ServiceHost.Unity { } public void WriteXml(XmlWriter writer) { - throw new System.NotImplementedException(); + foreach(var item in Items) { + var serializer = new XmlSerializer(item.GetType()); + serializer.Serialize(writer, item); + } } } } \ No newline at end of file diff --git a/Implab.ServiceHost/Unity/RegisterElement.cs b/Implab.ServiceHost/Unity/RegisterElement.cs --- a/Implab.ServiceHost/Unity/RegisterElement.cs +++ b/Implab.ServiceHost/Unity/RegisterElement.cs @@ -9,23 +9,11 @@ namespace Implab.ServiceHost.Unity { public class RegisterElement : AbstractRegistration { /// - /// An optional type specification for the service registration, - /// must be assignable from the type specified by - /// - [XmlAttribute("provides")] - public string ProvidesType { get; set; } - - /// - /// The type which is registered as a service in the container. + /// An optional type which is registered as a service in the container, must be assignable to . /// [XmlAttribute("type")] public string ImplementedType { get; set; } - [XmlElement("signleton", typeof(SimgletonLifetimeElement))] - [XmlElement("context", typeof(ContextLifetimeElement))] - [XmlElement("container", typeof(ContainerLifetimeElement))] - [XmlElement("hierarchy", typeof(HierarchicalLifetimeElement))] - public LifetimeElement Lifetime {get; set;} [XmlElement("constructor", typeof(ConstructorInjectionElement))] [XmlElement("property", typeof(PropertyInjectionElement))] diff --git a/Implab.ServiceHost/Unity/SerializedParameterElement.cs b/Implab.ServiceHost/Unity/SerializedParameterElement.cs --- a/Implab.ServiceHost/Unity/SerializedParameterElement.cs +++ b/Implab.ServiceHost/Unity/SerializedParameterElement.cs @@ -1,7 +1,12 @@ +using System.Xml; +using System.Xml.Schema; +using System.Xml.Serialization; + namespace Implab.ServiceHost.Unity { - public class SerializedParameterElement : InjectionParameterElement - { - + public class SerializedParameterElement : InjectionParameterElement { + + [XmlAnyElement] + public XmlElement[] Content { get; set; } } } \ No newline at end of file