Commit ef7433b

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-04-06 00:47:43
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@143 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 8574c80
Changed files (7)
trunk/product/MyMoney/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs
@@ -29,6 +29,7 @@ namespace MoMoney.boot.container.registration
 
             registry.transient(typeof (ITrackerEntryMapper<>), typeof (TrackerEntryMapper<>));
             registry.transient(typeof (IKey<>), typeof (TypedKey<>));
+            registry.transient(typeof (IComponentFactory<>), typeof (Factory<>));
             registry.singleton<IContext, Context>();
         }
     }
trunk/product/MyMoney/Domain/accounting/billing/billing_extensions.cs → trunk/product/MyMoney/Domain/accounting/billing/BillingExtensions.cs
@@ -1,6 +1,6 @@
 namespace MoMoney.Domain.accounting.billing
 {
-    public static class billing_extensions
+    public static class BillingExtensions
     {
         public static bool is_not_paid(this IBill bill)
         {
trunk/product/MyMoney/Domain/accounting/billing/Company.cs
@@ -6,21 +6,22 @@ namespace MoMoney.Domain.accounting.billing
 {
     public interface ICompany : IEntity
     {
-        void issue_bill_to(IAccountHolder customer, DateTime that_is_due_on, IMoney for_amount);
         string name { get; }
+        void change_name_to(string company_name);
+        void issue_bill_to(IAccountHolder customer, DateTime that_is_due_on, IMoney for_amount);
         void pay(IAccountHolder person, IMoney amount, IDate date_of_payment);
     }
 
     [Serializable]
-    internal class Company : Entity<ICompany>, ICompany
+    public class Company : Entity<ICompany>, ICompany
     {
-        public Company(string name_of_the_company)
+        public string name { get; private set; }
+
+        public void change_name_to(string company_name)
         {
-            name = name_of_the_company;
+            name = company_name;
         }
 
-        public string name { get; private set; }
-
         public void issue_bill_to(IAccountHolder customer, DateTime that_is_due_on, IMoney for_amount)
         {
             customer.recieve(new Bill(this, for_amount, that_is_due_on));
trunk/product/MyMoney/Domain/accounting/billing/CompanyFactory.cs
@@ -0,0 +1,28 @@
+using MoMoney.Domain.repositories;
+using MoMoney.Utility.Core;
+
+namespace MoMoney.Domain.accounting.billing
+{
+    public interface ICompanyFactory : IFactory<ICompany>
+    {
+    }
+
+    public class CompanyFactory : ICompanyFactory
+    {
+        readonly IComponentFactory<Company> factory;
+        readonly ICompanyRepository companys;
+
+        public CompanyFactory(IComponentFactory<Company> factory, ICompanyRepository companys)
+        {
+            this.factory = factory;
+            this.companys = companys;
+        }
+
+        public ICompany create()
+        {
+            var company = factory.create();
+            companys.save(company);
+            return company;
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Tasks/application/RegisterNewCompanyCommand.cs
@@ -1,5 +1,4 @@
 using MoMoney.Domain.accounting.billing;
-using MoMoney.Domain.repositories;
 using MoMoney.Presentation.Presenters.billing.dto;
 using MoMoney.Utility.Core;
 
@@ -11,16 +10,18 @@ namespace MoMoney.Tasks.application
 
     public class RegisterNewCompanyCommand : IRegisterNewCompanyCommand
     {
-        readonly ICompanyRepository companys;
+        readonly ICompanyFactory factory;
 
-        public RegisterNewCompanyCommand(ICompanyRepository companys)
+        public RegisterNewCompanyCommand(ICompanyFactory factory)
         {
-            this.companys = companys;
+            this.factory = factory;
         }
 
         public void run(RegisterNewCompany item)
         {
-            companys.save(new Company(item.company_name));
+            factory
+                .create()
+                .change_name_to(item.company_name);
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Utility/Core/Factory.cs
@@ -0,0 +1,14 @@
+namespace MoMoney.Utility.Core
+{
+    public interface IComponentFactory<T> : IFactory<T> where T : new()
+    {
+    }
+
+    public class Factory<T> : IComponentFactory<T> where T : new()
+    {
+        public T create()
+        {
+            return new T();
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -183,6 +183,7 @@
     <Compile Include="DataAccess\repositories\BillRepositorySpecs.cs" />
     <Compile Include="DataAccess\repositories\CompanyRepository.cs" />
     <Compile Include="DataAccess\repositories\IncomeRepository.cs" />
+    <Compile Include="Domain\accounting\billing\CompanyFactory.cs" />
     <Compile Include="Domain\accounting\billing\IEmployee.cs" />
     <Compile Include="Domain\accounting\financial_growth\income.cs" />
     <Compile Include="Domain\accounting\financial_growth\income_extensions.cs" />
@@ -196,7 +197,7 @@
     <Compile Include="DataAccess\core\IDatabaseGateway.cs" />
     <Compile Include="DataAccess\db40\SessionContext.cs" />
     <Compile Include="DataAccess\db40\SessionContextSpecs.cs" />
-    <Compile Include="Domain\accounting\billing\billing_extensions.cs" />
+    <Compile Include="Domain\accounting\billing\BillingExtensions.cs" />
     <Compile Include="Domain\accounting\billing\Company.cs" />
     <Compile Include="Domain\accounting\billing\CompanySpecs.cs" />
     <Compile Include="Domain\accounting\AccountHolder.cs" />
@@ -631,6 +632,7 @@
     <Compile Include="Utility\Core\DisposableCommand.cs" />
     <Compile Include="Utility\Core\EmptyCallback.cs" />
     <Compile Include="Utility\Core\EmptyCommand.cs" />
+    <Compile Include="Utility\Core\Factory.cs" />
     <Compile Include="Utility\Core\IBuilder.cs" />
     <Compile Include="Utility\Core\ICallback.cs" />
     <Compile Include="Utility\Core\IConfiguration.cs" />