##// END OF EJS Templates
Added IObservable to TraceRegistry
Added IObservable to TraceRegistry

File last commit:

r280:f07be402ab02 v3
r288:90cef6117ced v3
Show More
ContainerConfigurationSchema.cs
69 lines | 2.5 KiB | text/x-csharp | CSharpLexer
/ Implab.ServiceHost / Unity / ContainerConfigurationSchema.cs
cin
Working on Unity xml configuration: Refactoring in progress
r273 using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Serialization;
using Implab.Components;
namespace Implab.ServiceHost.Unity {
public class ContainerConfigurationSchema {
public static ContainerConfigurationSchema Default { get; private set; } = CreateDefault();
readonly LazyAndWeak<XmlSerializer> m_seralizer;
readonly XmlAttributeOverrides m_overrides = new XmlAttributeOverrides();
readonly XmlAttributes m_containerItems = new XmlAttributes();
public XmlSerializer Serializer {
get {
return m_seralizer.Value;
}
}
public ContainerConfigurationSchema() {
m_overrides.Add(typeof(ContainerElement), nameof(ContainerElement.Items), m_containerItems);
m_seralizer = new LazyAndWeak<XmlSerializer>(() => new XmlSerializer(typeof(ContainerElement), m_overrides));
}
public void RegisterContainerElement(Type type, string name) {
Safe.ArgumentNotNull(type, nameof(type));
Safe.ArgumentNotEmpty(name, nameof(name));
cin
Refactoring...
r277 if(!type.IsSubclassOf(typeof(AbstractContainerItem)))
throw new Exception($"RegisterContainerElement '{name}': {type} must be subclass of {typeof(AbstractContainerItem)}");
cin
Working on Unity xml configuration: Refactoring in progress
r273
m_containerItems.XmlElements.Add(
new XmlElementAttribute(name, type)
);
}
cin
Refactoring...
r277 public void RegisterContainerElement<T>(string name) where T : AbstractContainerItem {
cin
Working on Unity xml configuration: Refactoring in progress
r273 RegisterContainerElement(typeof(T), name);
}
cin
Added Trace<T>.Debug(...) method for debug messages...
r280 public ContainerElement LoadConfig(string uri) {
using (var reader = XmlReader.Create(uri)) {
cin
Working on Unity xml configuration: Refactoring in progress
r273 return (ContainerElement)Serializer.Deserialize(reader);
}
}
static ContainerConfigurationSchema CreateDefault() {
var schema = new ContainerConfigurationSchema();
schema.RegisterContainerElement<RegisterElement>("register");
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 schema.RegisterContainerElement<FactoryElement>("factory");
cin
Unity xml configuration, alpha2
r274 schema.RegisterContainerElement<SerializedElement>("serialized");
schema.RegisterContainerElement<ValueElement>("value");
cin
Working on Unity xml configuration: Refactoring in progress
r273 schema.RegisterContainerElement<IncludeElement>("include");
schema.RegisterContainerElement<AssemblyElement>("assembly");
schema.RegisterContainerElement<NamespaceElement>("namespace");
return schema;
}
}
}