Mercurial > pub > ImplabNet
diff Implab.ServiceHost/Unity/ConfigurationContext.cs @ 269:ff581cff7003 v3
Working on Unity container xml configuration
author | cin |
---|---|
date | Tue, 24 Apr 2018 01:46:02 +0300 |
parents | 0be8a6ae8307 |
children | ade80d94dfb5 |
line wrap: on
line diff
--- a/Implab.ServiceHost/Unity/ConfigurationContext.cs Sun Apr 22 15:29:10 2018 +0300 +++ b/Implab.ServiceHost/Unity/ConfigurationContext.cs Tue Apr 24 01:46:02 2018 +0300 @@ -5,7 +5,9 @@ namespace Implab.ServiceHost.Unity { using System.Linq; + using System.Reflection; using System.Text; + using global::Unity; using static Trace<ConfigurationContext>; public class ConfigurationContext { @@ -14,7 +16,10 @@ LinkedListNode<string> m_insertAt; - public ConfigurationContext() { + readonly UnityContainer m_container; + + public ConfigurationContext(UnityContainer container) { + m_container = container ?? new UnityContainer(); m_insertAt = new LinkedListNode<string>(string.Empty); m_namespases.AddFirst(m_insertAt); } @@ -36,9 +41,9 @@ foreach (var ns in m_namespases) { var typeName = FormatName(new [] { ns, reference.Namespace, reference.TypeName}, argc, args, reference.IsArray); - var resolved = Type.GetType(typeName, false); + var resolved = ProbeType(typeName); if (resolved != null) { - Log("Probe succeed {0} in '{1}': {2} -> {3}", reference, ns, typeName, resolved.FullName); + Log("Probe succeed {0} in '{1}': {2} -> {3}", reference, ns, typeName, resolved.AssemblyQualifiedName); return resolved; } else { Log("Probe failed {0} in '{1}': {2}", reference, ns, typeName); @@ -48,6 +53,17 @@ throw new Exception($"Failed to resolve: {reference}"); } + Type ProbeType(string typeName) { + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + + foreach(var assembly in assemblies) { + var type = assembly.GetType(typeName); + if (type != null) + return type; + } + return null; + } + string FormatName(string[] parts, int argc, Type[] args, bool isArray) { var builder = new StringBuilder(); @@ -59,7 +75,7 @@ if (args!= null && args.Length > 0) { builder.Append('['); - builder.Append(string.Join(",", args.Select(x => x.FullName))); + builder.Append(string.Join(",", args.Select(x => $"[{x.AssemblyQualifiedName}]"))); builder.Append(']'); } @@ -73,7 +89,11 @@ return Resolve(TypeReference.Parse(typeReference)); } - public void Register(ServiceElement descriptor) { + public void Visist(AbstractRegistration descriptor) { + + } + + public void Include(string file) { }