changeset 271:d4d437ec4483 v3

Working on Unity xml configuration
author cin
date Wed, 25 Apr 2018 19:23:35 +0300
parents ade80d94dfb5
children 9d1cca834b05
files Implab.Playground/Program.cs Implab.ServiceHost/Unity/AbstractRegistration.cs Implab.ServiceHost/Unity/ConfigurationSchema.cs Implab.ServiceHost/Unity/ContainerElement.cs Implab.ServiceHost/Unity/RegisterElement.cs Implab.ServiceHost/Unity/SerializedParameterElement.cs
diffstat 6 files changed, 32 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/Implab.Playground/Program.cs	Wed Apr 25 04:44:40 2018 +0300
+++ b/Implab.Playground/Program.cs	Wed Apr 25 19:23:35 2018 +0300
@@ -43,8 +43,12 @@
         static void Main(string[] args) {
             var container = new UnityContainer();
 
+            var ctx = new ConfigurationContext(container);
+
             var conf = SerializationHelpers.DeserializeFromFile<ContainerElement>("data/sample.xml");
 
+            ctx.Visit(conf);
+
             Console.WriteLine($"Registrations: {conf.Items.Count}");
 
         }
--- a/Implab.ServiceHost/Unity/AbstractRegistration.cs	Wed Apr 25 04:44:40 2018 +0300
+++ b/Implab.ServiceHost/Unity/AbstractRegistration.cs	Wed Apr 25 19:23:35 2018 +0300
@@ -15,6 +15,18 @@
             get; set;
         }
 
+        [XmlElement("signleton", typeof(SimgletonLifetimeElement))]
+        [XmlElement("context", typeof(ContextLifetimeElement))]
+        [XmlElement("container", typeof(ContainerLifetimeElement))]
+        [XmlElement("hierarchy", typeof(HierarchicalLifetimeElement))]
+        public LifetimeElement Lifetime {get; set;}
+
+        /// <summary>
+        /// A type specification for the service registration, 
+        /// </summary>
+        [XmlAttribute("provides")]
+        public string ProvidesType { get; set; }
+
         public void Visit(ConfigurationContext context) {
             context.Visit(this);
         }
--- a/Implab.ServiceHost/Unity/ConfigurationSchema.cs	Wed Apr 25 04:44:40 2018 +0300
+++ b/Implab.ServiceHost/Unity/ConfigurationSchema.cs	Wed Apr 25 19:23:35 2018 +0300
@@ -38,6 +38,9 @@
             var schema  = new ConfigurationSchema();
 
             schema.DefineMapping<RegisterElement>();
+            schema.DefineMapping<IncludeElement>();
+            schema.DefineMapping<AssemblyElement>();
+            schema.DefineMapping<NamespaceElement>();
 
             return schema;
         }
--- a/Implab.ServiceHost/Unity/ContainerElement.cs	Wed Apr 25 04:44:40 2018 +0300
+++ b/Implab.ServiceHost/Unity/ContainerElement.cs	Wed Apr 25 19:23:35 2018 +0300
@@ -22,7 +22,10 @@
         }
 
         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
--- a/Implab.ServiceHost/Unity/RegisterElement.cs	Wed Apr 25 04:44:40 2018 +0300
+++ b/Implab.ServiceHost/Unity/RegisterElement.cs	Wed Apr 25 19:23:35 2018 +0300
@@ -9,23 +9,11 @@
     public class RegisterElement : AbstractRegistration  {
         
         /// <summary>
-        /// An optional type specification for the service registration, 
-        /// must be assignable from the type specified by <see cref="ImplementedType"/>
-        /// </summary>
-        [XmlAttribute("provides")]
-        public string ProvidesType { get; set; }
-
-        /// <summary>
-        /// 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 <see cref="ProvidesType">.
         /// </summary>
         [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))]
--- a/Implab.ServiceHost/Unity/SerializedParameterElement.cs	Wed Apr 25 04:44:40 2018 +0300
+++ b/Implab.ServiceHost/Unity/SerializedParameterElement.cs	Wed Apr 25 19:23:35 2018 +0300
@@ -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