##// END OF EJS Templates
Working on Unity xml configuration
Working on Unity xml configuration

File last commit:

r270:ade80d94dfb5 v3
r271:d4d437ec4483 v3
Show More
ConfigurationContext.cs
63 lines | 1.7 KiB | text/x-csharp | CSharpLexer
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Implab.Diagnostics;
namespace Implab.ServiceHost.Unity {
using System.Linq;
using System.Reflection;
using System.Text;
using global::Unity;
using Implab.Xml;
using static Trace<ConfigurationContext>;
public class ConfigurationContext {
readonly TypeResolver m_resolver;
readonly UnityContainer m_container;
public ConfigurationContext(UnityContainer container) {
m_container = container ?? new UnityContainer();
m_resolver = new TypeResolver();
}
public Type Resolve(string typeReference) {
return m_resolver.Resolve(TypeReference.Parse(typeReference));
}
internal void Visit(AbstractRegistration descriptor) {
}
internal void Visit(NamespaceElement namespaceElement) {
m_resolver.AddNamespace(namespaceElement.Name);
}
internal void Visit(AssemblyElement assemblyElement) {
Assembly.Load(assemblyElement.AssemblyName);
}
internal void Visit(IncludeElement includeElement) {
Include(includeElement.Href);
}
public void Include(string file) {
var includeContext = new ConfigurationContext(m_container);
includeContext.LoadConfig(file);
}
public void LoadConfig(string file) {
var config = SerializationHelpers.DeserializeFromFile<ContainerElement>(file);
Visit(config);
}
public void Visit(ContainerElement containerElement) {
foreach (var item in containerElement.Items)
item.Visit(this);
}
}
}