diff Implab.ServiceHost/Unity/ContainerBuilder.cs @ 279:8714471e8d78 v3

Container configuration cleanup, RC2
author cin
date Fri, 04 May 2018 18:12:42 +0300
parents 6691aff01de1
children f07be402ab02
line wrap: on
line diff
--- a/Implab.ServiceHost/Unity/ContainerBuilder.cs	Thu May 03 09:59:44 2018 +0300
+++ b/Implab.ServiceHost/Unity/ContainerBuilder.cs	Fri May 04 18:12:42 2018 +0300
@@ -7,11 +7,11 @@
 
         readonly TypeResolver m_resolver;
 
-        readonly UnityContainer m_container;
+        readonly IUnityContainer m_container;
 
         readonly ContainerConfigurationSchema m_schema;
 
-        public UnityContainer Container {
+        public IUnityContainer Container {
             get {
                 return m_container;
             }
@@ -20,66 +20,14 @@
         public ContainerBuilder() : this(null, null) {
         }
 
-        public ContainerBuilder(UnityContainer container, ContainerConfigurationSchema schema) {
+        public ContainerBuilder(IUnityContainer container, ContainerConfigurationSchema schema) {
             m_container = container ?? new UnityContainer();
             m_resolver = new TypeResolver();
             m_schema = schema ?? ContainerConfigurationSchema.Default;
         }
 
         public Type ResolveType(string typeReference) {
-            return m_resolver.Resolve(typeReference, true);
-        }
-
-
-        internal void Visit(TypeAbstractRegistration typeRegistration) {
-            var registrationType = typeRegistration.GetRegistrationType(ResolveType);
-            var implementationType = typeRegistration.GetImplementationType(ResolveType) ?? registrationType;
-
-            var registrationContext = new TypeRegistrationBuilder(
-                m_resolver,
-                registrationType,
-                implementationType
-            );
-
-            typeRegistration.Visit(registrationContext);
-
-            m_container.RegisterType(
-                registrationContext.RegistrationType,
-                registrationContext.ImplementationType,
-                typeRegistration.Name,
-                registrationContext.Lifetime,
-                registrationContext.Injections
-            );
-        }
-
-        internal void Visit(InstanceAbstractRegistration instanceRegistration) {
-            var registrationType = instanceRegistration.GetRegistrationType(ResolveType);
-
-            var builder = new InstanceRegistrationBuilder(m_resolver, registrationType);
-
-            instanceRegistration.Visit(builder);
-
-            m_container.RegisterInstance(
-                builder.ValueBuilder.ValueType,
-                instanceRegistration.Name,
-                builder.ValueBuilder.Value,
-                builder.Lifetime
-            );
-        }
-
-        internal void Visit(FactoryAbstractRegistratrion factoryRgistration) {
-            var registrationType = factoryRgistration.GetRegistrationType(ResolveType);
-
-            var builder = new FactoryRegistrationBuilder(registrationType);
-
-            factoryRgistration.Visit(builder);
-
-            m_container.RegisterType(
-                builder.RegistrationType,
-                factoryRgistration.Name,
-                builder.Lifetime,
-                builder.Factory
-            );
+            return string.IsNullOrEmpty(typeReference) ? null : m_resolver.Resolve(typeReference, true);
         }
 
         public void Visit(ITypeRegistration registration) {
@@ -136,25 +84,11 @@
             m_container.RegisterInstance(
                 builder.RegistrationType ?? builder.ValueBuilder.ValueType,
                 registration.Name,
-                builder.ValueBuilder.Injection,
+                builder.ValueBuilder.Value,
                 builder.Lifetime                
             );
         }
 
-        public void Visit(IFactoryRegistration registration) {
-            Safe.ArgumentNotNull(registration, nameof(registration));
-
-            var registrationType = registration.GetRegistrationType(this);
-
-            var builder = new FactoryRegistrationBuilder(registrationType);
-
-            if (registration.MemberInjections != null) {
-                foreach(var member in registration.MemberInjections)
-                    member?.Visit(builder);
-            }
-
-        }
-
         public void AddNamespace(string ns) {
             m_resolver.AddNamespace(ns);
         }