Commit f76fe6c

mo khan <mo@mokhan.ca>
2009-10-23 14:07:53
switched from singleton context to per thread context.
1 parent 9d86ea6
product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs
@@ -33,7 +33,8 @@ namespace MoMoney.boot.container.registration
             registry.transient(typeof (ITrackerEntryMapper<>), typeof (TrackerEntryMapper<>));
             registry.transient(typeof (IKey<>), typeof (TypedKey<>));
             registry.transient(typeof (ComponentFactory<>), typeof (DefaultConstructorFactory<>));
-            registry.singleton<IContext>(() => new Context(new Hashtable()));
+            //registry.singleton<IContext>(() => new Context(new Hashtable()));
+            registry.singleton<IContext>(() => new PerThread());
 
             registry.singleton(() => AsyncOperationManager.SynchronizationContext);
             registry.singleton<AsyncOperation>(() => AsyncOperationManager.CreateOperation(new object()));
product/Boot/boot/container/ComponentExclusionSpecificationSpecs.cs
@@ -92,7 +92,7 @@ namespace MoMoney.boot.container
 
     static public class FakeStaticClass {}
 
-    public class FakeEntity : IEntity
+    public class FakeEntity : Entity
     {
         public Id<Guid> id
         {
product/Boot/boot/container/type_extensions.cs
@@ -25,7 +25,7 @@ namespace MoMoney.boot.container
 
         static public Specification<Type> is_an_entity(this Type item)
         {
-            return new PredicateSpecification<Type>(x => typeof (IEntity).IsAssignableFrom(x));
+            return new PredicateSpecification<Type>(x => typeof (Entity).IsAssignableFrom(x));
         }
 
         static public Specification<Type> is_an_interface(this Type item)
product/Boot/boot/WindowsFormsApplication.cs
@@ -29,23 +29,21 @@ namespace MoMoney.boot
 
         public void run()
         {
-            var stopwatch = new Stopwatch();
-            stopwatch.Start();
-            Func<ISplashScreenPresenter> presenter = () => new SplashScreenPresenter();
-            presenter = presenter.memorize();
-
-            var startup_screen = new display_the_splash_screen(presenter).on_a_background_thread();
+            using (new LogTime())
+            {
+                Func<ISplashScreenPresenter> presenter = () => new SplashScreenPresenter();
+                presenter = presenter.memorize();
 
-            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
-            hookup
-                .the<global_error_handling>()
-                .then(startup_screen)
-                .then<wire_up_the_container>()
-                .then(new start_the_application(startup_screen))
-                .run();
+                var startup_screen = new display_the_splash_screen(presenter).on_a_background_thread();
 
-            stopwatch.Stop();
-            this.log().debug("application startup took: {0}", stopwatch.Elapsed);
+                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
+                hookup
+                    .the<global_error_handling>()
+                    .then(startup_screen)
+                    .then<wire_up_the_container>()
+                    .then(new start_the_application(startup_screen))
+                    .run();
+            }
             start();
         }
 
@@ -63,6 +61,23 @@ namespace MoMoney.boot
         }
     }
 
+    public class LogTime : IDisposable
+    {
+        Stopwatch stopwatch;
+
+        public LogTime()
+        {
+            stopwatch = new Stopwatch();
+            stopwatch.Start();
+        }
+
+        public void Dispose()
+        {
+            stopwatch.Stop();
+            this.log().debug("application startup took: {0}", stopwatch.Elapsed);
+        }
+    }
+
     public class ApplicationContainer : Container
     {
         readonly IServiceContainer container;
product/database/repositories/CompanyRepository.cs
@@ -24,14 +24,12 @@ namespace momoney.database.repositories
 
         public ICompany find_company_named(string name)
         {
-            return session
-                .all<ICompany>()
-                .SingleOrDefault(x => x.name.is_equal_to_ignoring_case(name));
+            return all().SingleOrDefault(x => x.name.is_equal_to_ignoring_case(name));
         }
 
         public ICompany find_company_by(Guid id)
         {
-            return session.all<ICompany>().SingleOrDefault(x => x.id.Equals(id));
+            return all().SingleOrDefault(x => x.id.Equals(id));
         }
 
         public void save(ICompany company)
product/Domain/Accounting/AccountHolder.cs
@@ -7,7 +7,7 @@ using MoMoney.Domain.Core;
 
 namespace MoMoney.Domain.accounting
 {
-    public interface IAccountHolder : IEntity
+    public interface IAccountHolder : Entity
     {
         void receive(IBill bill);
         void receive(IIncome income);
@@ -16,7 +16,7 @@ namespace MoMoney.Domain.accounting
     }
 
     [Serializable]
-    public class AccountHolder : Entity<IAccountHolder>, IAccountHolder
+    public class AccountHolder : GenericEntity<IAccountHolder>, IAccountHolder
     {
         IList<IBill> all_bills { get; set; }
         IList<IIncome> income_collected { get; set; }
product/Domain/Accounting/Bill.cs
@@ -6,7 +6,7 @@ using gorilla.commons.utility;
 
 namespace MoMoney.Domain.Accounting
 {
-    public interface IBill : IEntity
+    public interface IBill : Entity
     {
         bool is_paid_for();
         void pay(Money amount_to_pay);
@@ -16,7 +16,7 @@ namespace MoMoney.Domain.Accounting
     }
 
     [Serializable]
-    public class Bill : Entity<IBill>, IBill
+    public class Bill : GenericEntity<IBill>, IBill
     {
         IList<IPayment> payments { get; set; }
 
product/Domain/Accounting/Company.cs
@@ -5,7 +5,7 @@ using MoMoney.Domain.Core;
 
 namespace MoMoney.Domain.Accounting
 {
-    public interface ICompany : IEntity
+    public interface ICompany : Entity
     {
         string name { get; }
         void change_name_to(string company_name);
@@ -14,7 +14,7 @@ namespace MoMoney.Domain.Accounting
     }
 
     [Serializable]
-    public class Company : Entity<ICompany>, ICompany
+    public class Company : GenericEntity<ICompany>, ICompany
     {
         public string name { get; private set; }
 
product/Domain/Accounting/Income.cs
@@ -4,7 +4,7 @@ using MoMoney.Domain.Core;
 
 namespace MoMoney.Domain.Accounting
 {
-    public interface IIncome : IEntity
+    public interface IIncome : Entity
     {
         Date date_of_issue { get; }
         Money amount_tendered { get; }
@@ -12,7 +12,7 @@ namespace MoMoney.Domain.Accounting
     }
 
     [Serializable]
-    internal class Income : Entity<IIncome>, IIncome
+    internal class Income : GenericEntity<IIncome>, IIncome
     {
         public Income(Date date_of_issue, Money amount_tendered, ICompany company)
         {
product/Domain/Accounting/Payment.cs
@@ -3,13 +3,13 @@ using MoMoney.Domain.Core;
 
 namespace MoMoney.Domain.Accounting
 {
-    public interface IPayment : IEntity
+    public interface IPayment : Entity
     {
         Money apply_to(Money money);
     }
 
     [Serializable]
-    internal class Payment : Entity<IPayment>, IPayment
+    internal class Payment : GenericEntity<IPayment>, IPayment
     {
         Money amount_paid { get; set; }
 
product/Domain/Core/Entity.cs
@@ -3,41 +3,5 @@ using gorilla.commons.utility;
 
 namespace MoMoney.Domain.Core
 {
-    public interface IEntity : Identifiable<Guid> {}
-
-    [Serializable]
-    public abstract class Entity<T> : IEntity where T : class, IEntity
-    {
-        protected Entity()
-        {
-            id = Guid.NewGuid();
-        }
-
-        public Id<Guid> id { get; private set; }
-
-        public bool Equals(Entity<T> obj)
-        {
-            if (ReferenceEquals(null, obj)) return false;
-            if (ReferenceEquals(this, obj)) return true;
-            return obj.id.Equals(id);
-        }
-
-        public override bool Equals(object obj)
-        {
-            if (ReferenceEquals(null, obj)) return false;
-            if (ReferenceEquals(this, obj)) return true;
-            if (obj.GetType() != typeof (Entity<T>)) return false;
-            return Equals((Entity<T>) obj);
-        }
-
-        public override int GetHashCode()
-        {
-            return id.GetHashCode();
-        }
-
-        public override string ToString()
-        {
-            return "{0} id: {1}".formatted_using(base.ToString(), id);
-        }
-    }
+    public interface Entity : Identifiable<Guid> {}
 }
\ No newline at end of file
product/Domain/Core/GenericEntity.cs
@@ -0,0 +1,41 @@
+using System;
+using gorilla.commons.utility;
+
+namespace MoMoney.Domain.Core
+{
+    [Serializable]
+    public abstract class GenericEntity<T> : Entity where T : class, Entity
+    {
+        protected GenericEntity()
+        {
+            id = Guid.NewGuid();
+        }
+
+        public Id<Guid> id { get; private set; }
+
+        public bool Equals(GenericEntity<T> obj)
+        {
+            if (ReferenceEquals(null, obj)) return false;
+            if (ReferenceEquals(this, obj)) return true;
+            return obj.id.Equals(id);
+        }
+
+        public override bool Equals(object obj)
+        {
+            if (ReferenceEquals(null, obj)) return false;
+            if (ReferenceEquals(this, obj)) return true;
+            if (obj.GetType() != typeof (GenericEntity<T>)) return false;
+            return Equals((GenericEntity<T>) obj);
+        }
+
+        public override int GetHashCode()
+        {
+            return id.GetHashCode();
+        }
+
+        public override string ToString()
+        {
+            return "{0} id: {1}".formatted_using(base.ToString(), id);
+        }
+    }
+}
\ No newline at end of file
product/Domain/Domain.csproj
@@ -80,6 +80,7 @@
     <Compile Include="accounting\GeneralLedgerSpecs.cs" />
     <Compile Include="accounting\AnnualIncomeVisitor.cs" />
     <Compile Include="accounting\IncomeExtensions.cs" />
+    <Compile Include="core\GenericEntity.cs" />
     <Compile Include="core\Entity.cs" />
     <Compile Include="core\Money.cs" />
     <Compile Include="core\MoneyExtensions.cs" />
product/Presentation/Winforms/Views/AddBillPaymentView.cs
@@ -18,8 +18,7 @@ namespace MoMoney.Presentation.Winforms.Views
         public AddBillPaymentView()
         {
             InitializeComponent();
-            titled("Add Bill Payment")
-                .icon(ApplicationIcons.AddBillPayment);
+            titled("Add Bill Payment").icon(ApplicationIcons.AddBillPayment);
             ux_submit_button.Click += (sender, e) => submit_clicked(e);
             companies_list = ux_company_names.create_for<CompanyDTO>();
         }