##// END OF EJS Templates
preview version of Unity xml configuration
preview version of Unity xml configuration

File last commit:

r272:9d1cca834b05 v3
r272:9d1cca834b05 v3
Show More
ConfigurationContext.cs
77 lines | 2.4 KiB | text/x-csharp | CSharpLexer
cin
Implemented typereference parser
r268 using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Implab.Diagnostics;
namespace Implab.ServiceHost.Unity {
using System.Linq;
cin
Working on Unity container xml configuration
r269 using System.Reflection;
cin
Implemented typereference parser
r268 using System.Text;
cin
Working on Unity container xml configuration
r269 using global::Unity;
cin
preview version of Unity xml configuration
r272 using global::Unity.Registration;
cin
Working on Unity container xml configuration
r270 using Implab.Xml;
cin
Implemented typereference parser
r268 using static Trace<ConfigurationContext>;
public class ConfigurationContext {
cin
Working on Unity container xml configuration
r270 readonly TypeResolver m_resolver;
cin
preview version of Unity xml configuration
r272 readonly UnityContainer m_container;
cin
Implemented typereference parser
r268
cin
Working on Unity container xml configuration
r269 public ConfigurationContext(UnityContainer container) {
m_container = container ?? new UnityContainer();
cin
Working on Unity container xml configuration
r270 m_resolver = new TypeResolver();
cin
Implemented typereference parser
r268 }
cin
Working on Unity container xml configuration
r270 public Type Resolve(string typeReference) {
return m_resolver.Resolve(TypeReference.Parse(typeReference));
cin
Implemented typereference parser
r268 }
cin
preview version of Unity xml configuration
r272 internal void Visit(RegisterElement descriptor) {
var registrationContext = new RegistrationContext(m_resolver, descriptor.ProvidesType, descriptor.ImplementationType);
if (descriptor.Injectors != null) {
foreach (var injector in descriptor.Injectors) {
injector.Visit(registrationContext);
}
}
m_container.RegisterType(
registrationContext.RegistrationType,
registrationContext.ImplementationType,
descriptor.Name,
descriptor.Lifetime?.GetLifetimeManager(this),
registrationContext.Injections
);
cin
Working on Unity container xml configuration
r269 }
cin
Working on Unity container xml configuration
r270 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);
}
cin
Working on Unity container xml configuration
r269 public void Include(string file) {
cin
Working on Unity container xml configuration
r270 var includeContext = new ConfigurationContext(m_container);
includeContext.LoadConfig(file);
}
cin
Implemented typereference parser
r268
cin
Working on Unity container xml configuration
r270 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);
cin
Implemented typereference parser
r268 }
}
}