Commit 4358093

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-27 00:14:13
changes the singleton registration.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@114 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent d7fe04b
trunk/product/MyMoney/boot/container/registration/auto_wire_components_in_to_the.cs
@@ -1,6 +1,6 @@
 using System;
 using System.Reflection;
-using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.Container.Windsor.configuration;
 using MoMoney.Infrastructure.Extensions;
 using MoMoney.Infrastructure.reflection;
trunk/product/MyMoney/boot/container/registration/auto_wire_components_in_to_the_specs.cs
@@ -1,7 +1,7 @@
 using System;
 using developwithpassion.bdd.contexts;
 using MbUnit.Framework;
-using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.Container.Windsor.configuration;
 using MoMoney.Infrastructure.reflection;
 using MoMoney.Testing.spechelpers.contexts;
trunk/product/MyMoney/boot/container/registration/wire_up_the_data_access_components_into_the.cs
@@ -1,5 +1,5 @@
 using MoMoney.DataAccess.db40;
-using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Utility.Core;
 
 namespace MoMoney.boot.container.registration
trunk/product/MyMoney/boot/container/registration/wire_up_the_essential_services_into_the.cs
@@ -1,8 +1,6 @@
-using System.Threading;
-using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.Logging;
 using MoMoney.Infrastructure.Logging.Log4NetLogging;
-using MoMoney.Infrastructure.Threading;
 using MoMoney.Utility.Core;
 
 namespace MoMoney.boot.container.registration
@@ -18,7 +16,7 @@ namespace MoMoney.boot.container.registration
 
         public void run()
         {
-            registration.singleton<IDependencyRegistration>(registration);
+            registration.singleton<IDependencyRegistration>(() => registration);
             registration.singleton<ILogFactory, Log4NetLogFactory>();
         }
     }
trunk/product/MyMoney/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs
@@ -1,4 +1,4 @@
-using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.eventing;
 using MoMoney.Infrastructure.registries;
 using MoMoney.Infrastructure.Threading;
trunk/product/MyMoney/boot/container/registration/wire_up_the_mappers_in_to_the.cs
@@ -1,4 +1,4 @@
-using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Utility.Core;
 
 namespace MoMoney.boot.container.registration
trunk/product/MyMoney/boot/container/registration/wire_up_the_presentation_modules.cs
@@ -1,5 +1,5 @@
 using System.Reflection;
-using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Presentation.Core;
 using MoMoney.Presentation.Model.Menu.File;
 using MoMoney.Presentation.Model.Menu.Help;
trunk/product/MyMoney/boot/container/registration/wire_up_the_reports_in_to_the.cs
@@ -1,4 +1,4 @@
-using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Presentation.Views.billing;
 using MoMoney.Presentation.Views.reporting;
 using MoMoney.Utility.Core;
trunk/product/MyMoney/boot/container/registration/wire_up_the_services_in_to_the.cs
@@ -1,7 +1,7 @@
 using System;
 using MoMoney.DataAccess.core;
 using MoMoney.Domain.repositories;
-using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.interceptors;
 using MoMoney.Infrastructure.proxies;
 using MoMoney.Tasks.application;
trunk/product/MyMoney/boot/container/registration/wire_up_the_views_in_to_the.cs
@@ -1,5 +1,6 @@
 using System.Threading;
-using MoMoney.Infrastructure.Container.Windsor;
+using System.Windows.Forms;
+using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.proxies;
 using MoMoney.Infrastructure.Threading;
 using MoMoney.Presentation.Views;
@@ -27,11 +28,18 @@ namespace MoMoney.boot.container.registration
         public void run()
         {
             var shell = new ApplicationShell();
-            register.singleton<ISynchronizationContext>(new SynchronizedContext(SynchronizationContext.Current));
-            register.singleton<IShell>(shell);
+            register.singleton(
+                () =>
+                    {
+                        if (SynchronizationContext.Current == null)
+                        {
+                            SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());
+                        }
+                        return SynchronizationContext.Current;
+                    });
+            register.singleton<IShell>(() => shell);
             //register.proxy(new SynchronizedConfiguration<IShell>(), () => shell);
-            register.singleton(shell);
-
+            register.singleton(() => shell);
             register.transient<IAboutApplicationView, AboutTheApplicationView>();
             register.transient<ISplashScreenView, SplashScreenView>();
             register.transient<INavigationView, NavigationView>();
trunk/product/MyMoney/boot/container/wire_up_the_container.cs
@@ -41,7 +41,7 @@ namespace MoMoney.boot.container
 
             Func<IContainer> func = registry.build;
             var dependency_registry = new AutofacDependencyRegistry(func.memorize());
-            registry.singleton<IDependencyRegistry>(dependency_registry);
+            registry.singleton<IDependencyRegistry>(() => dependency_registry);
             resolve.initialize_with(dependency_registry);
         }
     }
trunk/product/MyMoney/Infrastructure/Container/Autofac/AutofacDependencyRegistryBuilder.cs
@@ -3,7 +3,6 @@ using Autofac;
 using Autofac.Builder;
 using Autofac.Modules;
 using AutofacContrib.DynamicProxy2;
-using MoMoney.Infrastructure.Container.Windsor;
 using MoMoney.Infrastructure.proxies;
 using MoMoney.Utility.Core;
 using MoMoney.Utility.Extensions;
@@ -30,9 +29,9 @@ namespace MoMoney.Infrastructure.Container.Autofac
             builder.Register<Implementation>().As<Contract>().SingletonScoped();
         }
 
-        public void singleton<Contract>(Contract instance_of_the_contract)
+        public void singleton<Contract>(Func<Contract> instance_of_the_contract)
         {
-            builder.Register(instance_of_the_contract).As<Contract>().SingletonScoped();
+            builder.Register(x => instance_of_the_contract()).As<Contract>().SingletonScoped();
         }
 
         public void transient<Contract, Implementation>() where Implementation : Contract
trunk/product/MyMoney/Infrastructure/Container/Windsor/WindsorDependencyRegistry.cs
@@ -40,6 +40,11 @@ namespace MoMoney.Infrastructure.Container.Windsor
             underlying_container.Kernel.AddComponentInstance<Interface>(instanceOfTheInterface);
         }
 
+        public void singleton<Contract>(Func<Contract> instance_of_the_contract)
+        {
+            underlying_container.Kernel.AddComponentInstance<Contract>(instance_of_the_contract());
+        }
+
         public void transient<Interface, Implementation>() where Implementation : Interface
         {
             transient(typeof (Interface), typeof (Implementation));
trunk/product/MyMoney/Infrastructure/Container/Windsor/IDependencyRegistration.cs → trunk/product/MyMoney/Infrastructure/Container/IDependencyRegistration.cs
@@ -2,12 +2,12 @@ using System;
 using MoMoney.Infrastructure.proxies;
 using MoMoney.Utility.Core;
 
-namespace MoMoney.Infrastructure.Container.Windsor
+namespace MoMoney.Infrastructure.Container
 {
-    public interface IDependencyRegistration// : IDependencyRegistry
+    public interface IDependencyRegistration
     {
         void singleton<Contract, Implementation>() where Implementation : Contract;
-        void singleton<Contract>(Contract instance_of_the_contract);
+        void singleton<Contract>(Func<Contract> instance_of_the_contract);
         void transient<Contract, Implementation>() where Implementation : Contract;
         void transient(Type contract, Type implementation);
         void proxy<T>(IConfiguration<IProxyBuilder<T>> configuration, Func<T> target);
trunk/product/MyMoney/Infrastructure/eventing/EventAggregatorSpecs.cs
@@ -1,4 +1,3 @@
-using System;
 using System.Data;
 using System.Threading;
 using developwithpassion.bdd.contexts;
trunk/product/MyMoney/Presentation/Presenters/Menu/ApplicationMenuModule.cs
@@ -26,10 +26,11 @@ namespace MoMoney.Presentation.Presenters.Menu
 
         public void run()
         {
-            broker.subscribe_to<NewProjectOpened>(this);
-            broker.subscribe_to<ClosingProjectEvent>(this);
-            broker.subscribe_to<SavedChangesEvent>(this);
-            broker.subscribe_to<UnsavedChangesEvent>(this);
+            //broker.subscribe_to<newprojectopened>(this);
+            //broker.subscribe_to<ClosingProjectEvent>(this);
+            //broker.subscribe_to<SavedChangesEvent>(this);
+            //broker.subscribe_to<UnsavedChangesEvent>(this);
+            broker.subscribe(this);
             command.run<IApplicationMenuPresenter>();
         }
 
trunk/product/MyMoney/MyMoney.csproj
@@ -229,7 +229,7 @@
     <Compile Include="Infrastructure\Container\Windsor\configuration\LogComponent.cs" />
     <Compile Include="Infrastructure\Container\Windsor\configuration\RegisterComponentContract.cs" />
     <Compile Include="Infrastructure\Container\Windsor\configuration\type_extensions.cs" />
-    <Compile Include="Infrastructure\Container\Windsor\IDependencyRegistration.cs" />
+    <Compile Include="Infrastructure\Container\IDependencyRegistration.cs" />
     <Compile Include="Infrastructure\Container\Windsor\WindsorContainerFactory.cs" />
     <Compile Include="Infrastructure\debugging\Launch.cs" />
     <Compile Include="Infrastructure\eventing\EventAggregator.cs" />