diff Implab.ServiceHost/Unity/ConfigurationContext.cs @ 272:9d1cca834b05 v3

preview version of Unity xml configuration
author cin
date Thu, 26 Apr 2018 03:14:54 +0300
parents ade80d94dfb5
children
line wrap: on
line diff
--- a/Implab.ServiceHost/Unity/ConfigurationContext.cs	Wed Apr 25 19:23:35 2018 +0300
+++ b/Implab.ServiceHost/Unity/ConfigurationContext.cs	Thu Apr 26 03:14:54 2018 +0300
@@ -8,6 +8,7 @@
     using System.Reflection;
     using System.Text;
     using global::Unity;
+    using global::Unity.Registration;
     using Implab.Xml;
     using static Trace<ConfigurationContext>;
 
@@ -15,10 +16,8 @@
 
         readonly TypeResolver m_resolver;
 
-        
+        readonly UnityContainer m_container;
 
-        readonly UnityContainer m_container;
-        
         public ConfigurationContext(UnityContainer container) {
             m_container = container ?? new UnityContainer();
             m_resolver = new TypeResolver();
@@ -29,8 +28,23 @@
             return m_resolver.Resolve(TypeReference.Parse(typeReference));
         }
 
-        internal void Visit(AbstractRegistration descriptor) {
-            
+        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
+            );
+
         }
 
         internal void Visit(NamespaceElement namespaceElement) {