Commit 7539d3a

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-24 21:26:02
trying to get the unit of work interceptors intercepting calls to the service layer.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@101 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 6bc4c9f
trunk/product/MyMoney/boot/container/registration/wire_up_the_presentation_modules.cs
@@ -1,6 +1,7 @@
 using System.Reflection;
 using MoMoney.Infrastructure.Container.Windsor;
 using MoMoney.Presentation.Core;
+using MoMoney.Presentation.Presenters.Commands;
 using MoMoney.Utility.Core;
 using MoMoney.Utility.Extensions;
 
@@ -17,6 +18,7 @@ namespace MoMoney.boot.container.registration
 
         public void run()
         {
+            registry.transient(typeof (IRunThe<>), typeof (RunThe<>));
             Assembly
                 .GetExecutingAssembly()
                 .GetTypes()
trunk/product/MyMoney/boot/container/registration/wire_up_the_services_in_to_the.cs
@@ -1,4 +1,8 @@
+using System;
+using MoMoney.DataAccess.core;
+using MoMoney.Domain.repositories;
 using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.interceptors;
 using MoMoney.Infrastructure.proxies;
 using MoMoney.Presentation.Context;
 using MoMoney.Tasks.application;
@@ -18,15 +22,39 @@ namespace MoMoney.boot.container.registration
         public void run()
         {
             registry.singleton<the_application_context, the_application_context>();
-            //registry.proxy<IBillingTasks>(new ServiceLayerConfiguration<IBillingTasks>(), () => { return null; });
+            registry.proxy(new ServiceLayerConfiguration<IBillingTasks>(
+                               x =>
+                                   {
+                                       x.register_new_company(null);
+                                       x.save_a_new_bill_using(null);
+                                   }
+                               ),
+                           () =>
+                           new BillingTasks(Lazy.load<IBillRepository>(), Lazy.load<ICompanyRepository>(),
+                                            Lazy.load<ICustomerTasks>()));
+
+            registry.proxy(
+                new ServiceLayerConfiguration<ICustomerTasks>(x => x.get_the_current_customer()),
+                () => new CustomerTasks(Lazy.load<IDatabaseGateway>()));
+
+            registry.proxy(
+                new ServiceLayerConfiguration<IIncomeTasks>(x => x.add_new(null)),
+                () => new IncomeTasks(Lazy.load<IDatabaseGateway>(), Lazy.load<ICustomerTasks>()));
         }
     }
 
-    internal class ServiceLayerConfiguration<T> : IConfiguration<IProxyBuilder<IBillingTasks>>
+    internal class ServiceLayerConfiguration<T> : IConfiguration<IProxyBuilder<T>>
     {
-        public void configure(IProxyBuilder<IBillingTasks> item)
+        readonly Action<T> configure_it;
+
+        public ServiceLayerConfiguration(Action<T> configure_it)
+        {
+            this.configure_it = configure_it;
+        }
+
+        public void configure(IProxyBuilder<T> item)
         {
-            //item.add_interceptor<UnitOfWorkInterceptor>()
+            configure_it(item.add_interceptor(Lazy.load<IUnitOfWorkInterceptor>()).InterceptOn);
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/boot/container/wire_up_the_container.cs
@@ -20,6 +20,7 @@ namespace MoMoney.boot.container
             var configuration = new ComponentRegistrationConfiguration();
 
             new wire_up_the_essential_services_into_the(registry)
+                .then(new auto_wire_components_in_to_the(registry, specification))
                 .then(new wire_up_the_data_access_components_into_the(registry))
                 .then(new wire_up_the_infrastructure_in_to_the(registry))
                 .then(new wire_up_the_mappers_in_to_the(registry))
@@ -28,7 +29,6 @@ namespace MoMoney.boot.container
                 .then(new wire_up_the_views_in_to_the(registry))
                 .then(new wire_up_the_reports_in_to_the(registry))
                 //.then(new run_mass_component_registration_in_to_the(container, specification, configuration))
-                .then(new auto_wire_components_in_to_the(registry, specification))
                 .run();
 
             Func<IContainer> func = registry.build;
trunk/product/MyMoney/Infrastructure/proxies/ProxyBuilder.cs
@@ -8,6 +8,9 @@ namespace MoMoney.Infrastructure.proxies
 {
     public interface IProxyBuilder<TypeToProxy>
     {
+        IConstraintSelector<TypeToProxy> add_interceptor<Interceptor>(Interceptor interceptor)
+            where Interceptor : IInterceptor;
+
         IConstraintSelector<TypeToProxy> add_interceptor<Interceptor>() where Interceptor : IInterceptor, new();
         TypeToProxy create_proxy_for(TypeToProxy target);
         TypeToProxy create_proxy_for(Func<TypeToProxy> target);
@@ -30,14 +33,19 @@ namespace MoMoney.Infrastructure.proxies
             constraints = new Dictionary<IInterceptor, IInterceptorConstraint<TypeToProxy>>();
         }
 
-
-        public IConstraintSelector<TypeToProxy> add_interceptor<Interceptor>() where Interceptor : IInterceptor, new()
+        public IConstraintSelector<TypeToProxy> add_interceptor<Interceptor>(Interceptor interceptor)
+            where Interceptor : IInterceptor
         {
             var constraint = constraint_factory.CreateFor<TypeToProxy>();
-            constraints.Add(new Interceptor(), constraint);
+            constraints.Add(interceptor, constraint);
             return constraint;
         }
 
+        public IConstraintSelector<TypeToProxy> add_interceptor<Interceptor>() where Interceptor : IInterceptor, new()
+        {
+            return add_interceptor(new Interceptor());
+        }
+
         public TypeToProxy create_proxy_for(TypeToProxy target)
         {
             return create_proxy_for(() => target);
trunk/product/MyMoney/Presentation/Model/Navigation/branches/add_bill_payment_branch.cs
@@ -6,16 +6,16 @@ namespace MoMoney.Presentation.Model.Navigation.branches
 {
     public class add_bill_payment_branch : IBranchVisitor
     {
-        private readonly IRunThe<IAddBillPaymentPresenter> command;
+        readonly IRunPresenterCommand command;
 
-        public add_bill_payment_branch(IRunThe<IAddBillPaymentPresenter> command)
+        public add_bill_payment_branch(IRunPresenterCommand command)
         {
             this.command = command;
         }
 
         public void visit(ITreeBranch item_to_visit)
         {
-            item_to_visit.add_child("Bill Payments", ApplicationIcons.AddIncome, command);
+            item_to_visit.add_child("Bill Payments", ApplicationIcons.AddIncome, () => command.run<IAddBillPaymentPresenter>());
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Navigation/branches/add_new_bill_branch.cs
@@ -6,16 +6,16 @@ namespace MoMoney.Presentation.Model.Navigation.branches
 {
     public class add_new_bill_branch : IBranchVisitor
     {
-        private readonly IRunThe<IAddCompanyPresenter> command;
+        readonly IRunPresenterCommand command;
 
-        public add_new_bill_branch(IRunThe<IAddCompanyPresenter> command)
+        public add_new_bill_branch(IRunPresenterCommand command)
         {
             this.command = command;
         }
 
         public void visit(ITreeBranch item_to_visit)
         {
-            item_to_visit.add_child("Add Bills", ApplicationIcons.AddIncome, command);
+            item_to_visit.add_child("Add Bills", ApplicationIcons.AddIncome, () => command.run<IAddCompanyPresenter>());
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Navigation/tree_branch.cs
@@ -1,3 +1,4 @@
+using System;
 using System.Drawing;
 using System.Windows.Forms;
 using MoMoney.Presentation.Resources;
@@ -9,12 +10,13 @@ namespace MoMoney.Presentation.Model.Navigation
     {
         void accept(IVisitor<ITreeBranch> visitor);
         ITreeBranch add_child(string name, ApplicationIcon icon, ICommand command);
+        ITreeBranch add_child(string name, ApplicationIcon icon, Action command);
     }
 
     public class tree_branch : ITreeBranch
     {
-        private readonly TreeNode node;
-        private readonly ICommand the_command;
+        readonly TreeNode node;
+        readonly ICommand the_command;
 
         public tree_branch(TreeNode node, ICommand the_command)
         {
@@ -30,22 +32,30 @@ namespace MoMoney.Presentation.Model.Navigation
 
         public ITreeBranch add_child(string name, ApplicationIcon icon, ICommand command)
         {
-            var new_node = new TreeNode(name) {
-                                                  ImageKey = icon.name_of_the_icon,
-                                                  SelectedImageKey = icon.name_of_the_icon
-                                              };
+            var new_node = new TreeNode(name)
+                               {
+                                   ImageKey = icon.name_of_the_icon,
+                                   SelectedImageKey = icon.name_of_the_icon
+                               };
             node.Nodes.Add(new_node);
             return new tree_branch(new_node, command);
         }
 
-        private void Click()
+        public ITreeBranch add_child(string name, ApplicationIcon icon, Action command)
         {
-            if (node.Equals(node.TreeView.SelectedNode)) {
+            return add_child(name, icon, new ActionCommand(command));
+        }
+
+        void Click()
+        {
+            if (node.Equals(node.TreeView.SelectedNode))
+            {
                 node.Expand();
                 the_command.run();
                 node.BackColor = Color.HotPink;
             }
-            else {
+            else
+            {
                 node.BackColor = Color.Empty;
             }
         }
trunk/product/MyMoney/Presentation/Presenters/Commands/run_the_specs.cs
@@ -6,9 +6,9 @@ using MoMoney.Testing.spechelpers.core;
 
 namespace MoMoney.Presentation.Presenters.Commands
 {
-    [Concern(typeof (run_the<>))]
+    [Concern(typeof (RunThe<>))]
     public class when_initializing_different_regions_of_the_user_interface :
-        concerns_for<IRunThe<IPresenter>, run_the<IPresenter>>
+        concerns_for<IRunThe<IPresenter>, RunThe<IPresenter>>
     {
         it should_initialize_the_presenter_that_controls_that_region =
             () => application_controller.was_told_to(x => x.run<IPresenter>());
trunk/product/MyMoney/Presentation/Presenters/Commands/run_the.cs → trunk/product/MyMoney/Presentation/Presenters/Commands/RunThe.cs
@@ -7,11 +7,11 @@ namespace MoMoney.Presentation.Presenters.Commands
     {
     }
 
-    public class run_the<Presenter> : IRunThe<Presenter> where Presenter : IPresenter
+    public class RunThe<Presenter> : IRunThe<Presenter> where Presenter : IPresenter
     {
         readonly IApplicationController applicationController;
 
-        public run_the(IApplicationController applicationController)
+        public RunThe(IApplicationController applicationController)
         {
             this.applicationController = applicationController;
         }
trunk/product/MyMoney/Utility/Core/ActionCommand.cs
@@ -4,7 +4,7 @@ namespace MoMoney.Utility.Core
 {
     public class ActionCommand : ICommand
     {
-        Action action;
+        readonly Action action;
 
         public ActionCommand(Action action)
         {
trunk/product/MyMoney/MyMoney.csproj
@@ -357,7 +357,7 @@
     <Compile Include="Presentation\Presenters\billing\ViewAllBillsPresenter.cs" />
     <Compile Include="Presentation\Presenters\Commands\RestartCommand.cs" />
     <Compile Include="Presentation\Presenters\Commands\RunPresenterCommand.cs" />
-    <Compile Include="Presentation\Presenters\Commands\run_the.cs" />
+    <Compile Include="Presentation\Presenters\Commands\RunThe.cs" />
     <Compile Include="Presentation\Presenters\Commands\run_the_specs.cs" />
     <Compile Include="Presentation\Presenters\excel\Cell.cs" />
     <Compile Include="Presentation\Presenters\excel\excel_usage.cs" />