##// END OF EJS Templates
Fixed promise rejection when there is not specified error handler in the reaction....
Fixed promise rejection when there is not specified error handler in the reaction. FIXED SPELLING IN THE XML CONTAINER CONFIGURATION signleton->singleton Code cleanup Update tests make them working on dotnet core

File last commit:

r295:28af686e24f7 default
r295:28af686e24f7 default
Show More
ContainerConfigurationSchema.cs
66 lines | 2.4 KiB | text/x-csharp | CSharpLexer
/ Implab.ServiceHost / src / Unity / ContainerConfigurationSchema.cs
using System;
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));
if(!type.IsSubclassOf(typeof(AbstractContainerItem)))
throw new Exception($"RegisterContainerElement '{name}': {type} must be subclass of {typeof(AbstractContainerItem)}");
m_containerItems.XmlElements.Add(
new XmlElementAttribute(name, type)
);
}
public void RegisterContainerElement<T>(string name) where T : AbstractContainerItem {
RegisterContainerElement(typeof(T), name);
}
public ContainerElement LoadConfig(string uri) {
using (var reader = XmlReader.Create(uri)) {
return (ContainerElement)Serializer.Deserialize(reader);
}
}
static ContainerConfigurationSchema CreateDefault() {
var schema = new ContainerConfigurationSchema();
schema.RegisterContainerElement<RegisterElement>("register");
schema.RegisterContainerElement<FactoryElement>("factory");
schema.RegisterContainerElement<SerializedElement>("serialized");
schema.RegisterContainerElement<ValueElement>("value");
schema.RegisterContainerElement<IncludeElement>("include");
schema.RegisterContainerElement<AssemblyElement>("assembly");
schema.RegisterContainerElement<NamespaceElement>("namespace");
return schema;
}
}
}