Commit 3ed7da1

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-04-30 20:15:36
refactored out some domain to dto mappers.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@200 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent d6420cf
trunk/product/MoMoney.Domain/Accounting/Bill.cs
@@ -2,7 +2,6 @@ using System;
 using System.Collections.Generic;
 using Gorilla.Commons.Utility;
 using Gorilla.Commons.Utility.Extensions;
-using MoMoney.Domain.accounting.billing;
 using MoMoney.Domain.Core;
 
 namespace MoMoney.Domain.Accounting
trunk/product/MoMoney.Domain/Accounting/IInvoice.cs
@@ -1,10 +0,0 @@
-using MoMoney.Domain.Core;
-
-namespace MoMoney.Domain.accounting
-{
-    public interface IInvoice
-    {
-        void pay(Money two_thousand_dollars);
-        Money total();
-    }
-}
\ No newline at end of file
trunk/product/MoMoney.Domain/Accounting/Payment.cs
@@ -5,18 +5,23 @@ namespace MoMoney.Domain.Accounting
 {
     public interface IPayment : IEntity
     {
-        Money amount_paid { get; }
+        Money apply_to(Money money);
     }
 
     [Serializable]
     internal class Payment : Entity<IPayment>, IPayment
     {
+        Money amount_paid { get; set; }
+
         public Payment(Money amount_paid)
         {
             this.amount_paid = amount_paid;
         }
 
-        public Money amount_paid { get; private set; }
+        public Money apply_to(Money money)
+        {
+            return money.add(amount_paid);
+        }
 
         public bool Equals(Payment obj)
         {
@@ -34,7 +39,8 @@ namespace MoMoney.Domain.Accounting
 
         public override int GetHashCode()
         {
-            unchecked {
+            unchecked
+            {
                 return (base.GetHashCode()*397) ^ (amount_paid != null ? amount_paid.GetHashCode() : 0);
             }
         }
trunk/product/MoMoney.Domain/Accounting/TotalPaymentsCalculator.cs
@@ -1,8 +1,7 @@
 using Gorilla.Commons.Utility.Core;
-using MoMoney.Domain.Accounting;
 using MoMoney.Domain.Core;
 
-namespace MoMoney.Domain.accounting.billing
+namespace MoMoney.Domain.Accounting
 {
     internal class TotalPaymentsCalculator : IValueReturningVisitor<Money, IPayment>
     {
@@ -13,7 +12,7 @@ namespace MoMoney.Domain.accounting.billing
 
         public void visit(IPayment payment)
         {
-            value = value.add(payment.amount_paid);
+            value = payment.apply_to(value);
         }
 
         public Money value { get; private set; }
trunk/product/MoMoney.Domain/MoMoney.Domain.csproj
@@ -72,7 +72,6 @@
     <Compile Include="Accounting\GeneralLedgerSpecs.cs" />
     <Compile Include="Accounting\AnnualIncomeVisitor.cs" />
     <Compile Include="Accounting\IncomeExtensions.cs" />
-    <Compile Include="Accounting\IInvoice.cs" />
     <Compile Include="Core\Entity.cs" />
     <Compile Include="Core\Money.cs" />
     <Compile Include="Core\MoneyExtensions.cs" />
trunk/product/MoMoney.Service/Application/GetAllBillsQuery.cs
@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using Gorilla.Commons.Utility.Core;
 using Gorilla.Commons.Utility.Extensions;
 using MoMoney.Domain.Accounting;
 using MoMoney.Domain.repositories;
@@ -9,25 +10,17 @@ namespace MoMoney.Service.Application
     public class GetAllBillsQuery : IGetAllBillsQuery
     {
         readonly IBillRepository bills;
+        readonly IMapper<IBill, BillInformationDTO> mapper;
 
-        public GetAllBillsQuery(IBillRepository bills)
+        public GetAllBillsQuery(IBillRepository bills, IMapper<IBill, BillInformationDTO> mapper)
         {
             this.bills = bills;
+            this.mapper = mapper;
         }
 
         public IEnumerable<BillInformationDTO> fetch()
         {
-            return bills.all().map_all_using(x => map_from(x));
-        }
-
-        BillInformationDTO map_from(IBill bill)
-        {
-            return new BillInformationDTO
-                       {
-                           company_name = bill.company_to_pay.name,
-                           the_amount_owed = bill.the_amount_owed.ToString(),
-                           due_date = bill.due_date.to_date_time(),
-                       };
+            return bills.all().map_all_using(mapper);
         }
     }
 }
\ No newline at end of file
trunk/product/MoMoney.Service/Application/GetAllCompanysQuery.cs
@@ -1,5 +1,7 @@
 using System.Collections.Generic;
+using Gorilla.Commons.Utility.Core;
 using Gorilla.Commons.Utility.Extensions;
+using MoMoney.Domain.Accounting;
 using MoMoney.Domain.repositories;
 using MoMoney.DTO;
 
@@ -8,15 +10,17 @@ namespace MoMoney.Service.Application
     public class GetAllCompanysQuery : IGetAllCompanysQuery
     {
         readonly ICompanyRepository companys;
+        readonly IMapper<ICompany, CompanyDTO> mapper;
 
-        public GetAllCompanysQuery(ICompanyRepository companys)
+        public GetAllCompanysQuery(ICompanyRepository companys, IMapper<ICompany, CompanyDTO> mapper)
         {
             this.companys = companys;
+            this.mapper = mapper;
         }
 
         public IEnumerable<CompanyDTO> fetch()
         {
-            return companys.all().map_all_using(x => new CompanyDTO {id = x.id, name = x.name});
+            return companys.all().map_all_using(mapper);
         }
     }
 }
\ No newline at end of file
trunk/product/MoMoney.Service/Application/GetAllIncomeQuery.cs
@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using Gorilla.Commons.Utility.Core;
 using Gorilla.Commons.Utility.Extensions;
 using MoMoney.Domain.Accounting;
 using MoMoney.Domain.repositories;
@@ -9,25 +10,17 @@ namespace MoMoney.Service.Application
     public class GetAllIncomeQuery : IGetAllIncomeQuery
     {
         readonly IIncomeRepository all_income;
+        readonly IMapper<IIncome, IncomeInformationDTO> mapper;
 
-        public GetAllIncomeQuery(IIncomeRepository all_income)
+        public GetAllIncomeQuery(IIncomeRepository all_income, IMapper<IIncome, IncomeInformationDTO> mapper)
         {
             this.all_income = all_income;
+            this.mapper = mapper;
         }
 
         public IEnumerable<IncomeInformationDTO> fetch()
         {
-            return all_income.all().map_all_using(x => map_from(x));
-        }
-
-        static IncomeInformationDTO map_from(IIncome x)
-        {
-            return new IncomeInformationDTO
-                       {
-                           amount = x.amount_tendered.to_string(),
-                           company = x.company.to_string(),
-                           recieved_date = x.date_of_issue.to_string(),
-                       };
+            return all_income.all().map_all_using(mapper);
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/auto_wire_components_in_to_the.cs
@@ -3,15 +3,10 @@ using System.Reflection;
 using Gorilla.Commons.Infrastructure;
 using Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration;
 using Gorilla.Commons.Infrastructure.Reflection;
-using Gorilla.Commons.Utility.Core;
 using Gorilla.Commons.Utility.Extensions;
 
 namespace MoMoney.boot.container.registration
 {
-    public interface IStartupCommand : ICommand, IParameterizedCommand<IAssembly>
-    {
-    }
-
     public class auto_wire_components_in_to_the : IStartupCommand
     {
         readonly IDependencyRegistration registrar;
trunk/product/MyMoney/boot/container/registration/IStartupCommand.cs
@@ -0,0 +1,9 @@
+using Gorilla.Commons.Infrastructure.Reflection;
+using Gorilla.Commons.Utility.Core;
+
+namespace MoMoney.boot.container.registration
+{
+    public interface IStartupCommand : ICommand, IParameterizedCommand<IAssembly>
+    {
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/wire_up_the_essential_services_into_the.cs
@@ -1,7 +1,5 @@
 using System.ComponentModel;
 using System.Deployment.Application;
-using System.Threading;
-using System.Windows.Forms;
 using Gorilla.Commons.Infrastructure;
 using Gorilla.Commons.Infrastructure.Container;
 using Gorilla.Commons.Infrastructure.Log4Net;
@@ -27,19 +25,10 @@ namespace MoMoney.boot.container.registration
             registration.singleton<IDependencyRegistry>(() => registration.build());
             registration.singleton<ILogFactory, Log4NetLogFactory>();
             registration.singleton<ICommandProcessor, AsynchronousCommandProcessor>();
-            registration.singleton(
-                () =>
-                    {
-                        return AsyncOperationManager.SynchronizationContext;
-                        //if (SynchronizationContext.Current == null)
-                        //{
-                        //    SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());
-                        //}
-                        //return SynchronizationContext.Current;
-                    });
-            registration.singleton<AsyncOperation>(() => AsyncOperationManager.CreateOperation(null));
-            registration.singleton<ApplicationDeployment>(() => ApplicationDeployment.IsNetworkDeployed ? ApplicationDeployment.CurrentDeployment : null);
-            registration.singleton<IDeployment>(() => ApplicationDeployment.IsNetworkDeployed ? (IDeployment)new CurrentDeployment() : (IDeployment)new NullDeployment());
+            registration.singleton(() => AsyncOperationManager.SynchronizationContext);
+            registration.singleton<AsyncOperation>(() => AsyncOperationManager.CreateOperation(new object()));
+            registration.singleton<ApplicationDeployment>( () => ApplicationDeployment.IsNetworkDeployed ? ApplicationDeployment.CurrentDeployment : null);
+            registration.singleton<IDeployment>( () => ApplicationDeployment.IsNetworkDeployed ? (IDeployment) new CurrentDeployment() : (IDeployment) new NullDeployment());
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs
@@ -4,7 +4,6 @@ using Gorilla.Commons.Infrastructure.Registries;
 using Gorilla.Commons.Infrastructure.Threading;
 using Gorilla.Commons.Infrastructure.Transactions;
 using Gorilla.Commons.Utility.Core;
-//using MoMoney.Infrastructure.transactions;
 using MoMoney.Presentation.Model.Projects;
 
 namespace MoMoney.boot.container.registration
trunk/product/MyMoney/boot/container/registration/wire_up_the_mappers_in_to_the.cs
@@ -1,11 +1,15 @@
+using System;
 using Gorilla.Commons.Infrastructure;
 using Gorilla.Commons.Utility.Core;
+using Gorilla.Commons.Utility.Extensions;
+using MoMoney.Domain.Accounting;
+using MoMoney.DTO;
 
 namespace MoMoney.boot.container.registration
 {
     internal class wire_up_the_mappers_in_to_the : ICommand
     {
-        private readonly IDependencyRegistration registry;
+        readonly IDependencyRegistration registry;
 
         public wire_up_the_mappers_in_to_the(IDependencyRegistration registry)
         {
@@ -14,8 +18,23 @@ namespace MoMoney.boot.container.registration
 
         public void run()
         {
-            //registry.register<IMapper<ISubMenu, ToolStripMenuItem>, sub_menu_to_tool_strip_menu_item_mapper>();
-            //registry.register<IMapper<TreeView, ITreeBranch>, tree_view_to_root_node_mapper>();
+            registry.transient(typeof (IMapper<,>), typeof (Map<,>));
+            registry.singleton<Converter<IBill, BillInformationDTO>>(
+                () => x => new BillInformationDTO
+                               {
+                                   company_name = x.company_to_pay.name,
+                                   the_amount_owed = x.the_amount_owed.ToString(),
+                                   due_date = x.due_date.to_date_time(),
+                               });
+            registry.singleton<Converter<ICompany, CompanyDTO>>(() => x => new CompanyDTO {id = x.id, name = x.name});
+
+            registry.singleton<Converter<IIncome, IncomeInformationDTO>>(
+                () => x => new IncomeInformationDTO
+                               {
+                                   amount = x.amount_tendered.to_string(),
+                                   company = x.company.to_string(),
+                                   recieved_date = x.date_of_issue.to_string(),
+                               });
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/wire_up_the_services_in_to_the.cs
@@ -3,6 +3,7 @@ using Gorilla.Commons.Utility.Core;
 using MoMoney.boot.container.registration.proxy_configuration;
 using MoMoney.Domain.Accounting;
 using MoMoney.Domain.repositories;
+using MoMoney.DTO;
 using MoMoney.Service.Application;
 
 namespace MoMoney.boot.container.registration
@@ -28,11 +29,11 @@ namespace MoMoney.boot.container.registration
         void wire_up_queries()
         {
             registry.proxy<IGetAllCompanysQuery, ServiceLayerConfiguration<IGetAllCompanysQuery>>(
-                () => new GetAllCompanysQuery(Lazy.load<ICompanyRepository>()));
+                () => new GetAllCompanysQuery(Lazy.load<ICompanyRepository>(),Lazy.load<IMapper<ICompany, CompanyDTO>>()));
             registry.proxy<IGetAllBillsQuery, ServiceLayerConfiguration<IGetAllBillsQuery>>(
-                () => new GetAllBillsQuery(Lazy.load<IBillRepository>()));
+                () => new GetAllBillsQuery(Lazy.load<IBillRepository>(), Lazy.load<IMapper<IBill, BillInformationDTO>>()));
             registry.proxy<IGetAllIncomeQuery, ServiceLayerConfiguration<IGetAllIncomeQuery>>(
-                () => new GetAllIncomeQuery(Lazy.load<IIncomeRepository>()));
+                () => new GetAllIncomeQuery(Lazy.load<IIncomeRepository>(),Lazy.load<IMapper<IIncome, IncomeInformationDTO>>()));
         }
 
         void wire_up_the_commands()
trunk/product/MyMoney/MyMoney.csproj
@@ -166,6 +166,7 @@
     </Compile>
     <Compile Include="boot\container\registration\auto_wire_components_in_to_the.cs" />
     <Compile Include="boot\container\registration\auto_wire_components_in_to_the_specs.cs" />
+    <Compile Include="boot\container\registration\IStartupCommand.cs" />
     <Compile Include="boot\container\registration\proxy_configuration\NoConfiguration.cs" />
     <Compile Include="boot\container\registration\proxy_configuration\ServiceLayerConfiguration.cs" />
     <Compile Include="boot\container\registration\proxy_configuration\SynchronizedConfiguration.cs" />