Commit 9c9eee7

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-27 04:11:20
cleaned up the container registration.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@117 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 88e6920
trunk/product/MyMoney/boot/container/registration/wire_up_the_essential_services_into_the.cs
@@ -18,6 +18,7 @@ namespace MoMoney.boot.container.registration
         public void run()
         {
             registration.singleton<IDependencyRegistration>(() => registration);
+            registration.singleton<IDependencyRegistry>(() => registration.build());
             registration.singleton<ILogFactory, Log4NetLogFactory>();
             registration.singleton<ICommandProcessor, AsynchronousCommandProcessor>();
         }
trunk/product/MyMoney/boot/container/wire_up_the_container.cs
@@ -1,5 +1,3 @@
-using System;
-using Autofac;
 using MoMoney.boot.container.registration;
 using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.Container.Autofac;
@@ -11,7 +9,7 @@ namespace MoMoney.boot.container
 {
     internal class wire_up_the_container : ICommand
     {
-        AutofacDependencyRegistryBuilder registry;
+        IDependencyRegistration registry;
         IComponentExclusionSpecification specification;
 
         public wire_up_the_container()
@@ -19,7 +17,7 @@ namespace MoMoney.boot.container
         {
         }
 
-        public wire_up_the_container(AutofacDependencyRegistryBuilder registry,
+        public wire_up_the_container(IDependencyRegistration registry,
                                      IComponentExclusionSpecification specification)
         {
             this.registry = registry;
@@ -39,10 +37,7 @@ namespace MoMoney.boot.container
                 .then(new wire_up_the_reports_in_to_the(registry))
                 .run();
 
-            Func<IContainer> func = registry.build;
-            var dependency_registry = new AutofacDependencyRegistry(func.memorize());
-            registry.singleton<IDependencyRegistry>(() => dependency_registry);
-            resolve.initialize_with(dependency_registry);
+            resolve.initialize_with(registry.build());
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/Autofac/AutofacDependencyRegistryBuilder.cs
@@ -9,9 +9,10 @@ using MoMoney.Utility.Extensions;
 
 namespace MoMoney.Infrastructure.Container.Autofac
 {
-    internal class AutofacDependencyRegistryBuilder : IDependencyRegistration, IBuilder<IContainer>
+    internal class AutofacDependencyRegistryBuilder : IDependencyRegistration //, IBuilder<IContainer>
     {
         readonly ContainerBuilder builder;
+        readonly Func<IContainer> container;
 
         public AutofacDependencyRegistryBuilder() : this(new ContainerBuilder())
         {
@@ -22,6 +23,8 @@ namespace MoMoney.Infrastructure.Container.Autofac
             this.builder = builder;
             builder.RegisterModule(new ImplicitCollectionSupportModule());
             builder.RegisterModule(new StandardInterceptionModule());
+            container = () => builder.Build();
+            container = container.memorize();
         }
 
         public void singleton<Contract, Implementation>() where Implementation : Contract
@@ -58,9 +61,9 @@ namespace MoMoney.Infrastructure.Container.Autofac
             builder.Register(x => proxy_builder.create_proxy_for(target)).As<T>().FactoryScoped();
         }
 
-        public IContainer build()
+        public IDependencyRegistry build()
         {
-            return builder.Build();
+            return new AutofacDependencyRegistry(container);
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/Windsor/WindsorDependencyRegistry.cs
@@ -68,5 +68,10 @@ namespace MoMoney.Infrastructure.Container.Windsor
             configuration.configure(builder);
             singleton(builder.create_proxy_for(target));
         }
+
+        public IDependencyRegistry build()
+        {
+            return this;
+        }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/IDependencyRegistration.cs
@@ -4,7 +4,7 @@ using MoMoney.Utility.Core;
 
 namespace MoMoney.Infrastructure.Container
 {
-    public interface IDependencyRegistration
+    public interface IDependencyRegistration : IBuilder<IDependencyRegistry>
     {
         void singleton<Contract, Implementation>() where Implementation : Contract;
         void singleton<Contract>(Func<Contract> instance_of_the_contract);