Commit eb992c0

mo <email@solidware.ca>
2011-03-29 03:23:18
resaving the person after altering it.
1 parent 78033b5
product/infrastructure/CastleProxyFactory.cs
@@ -1,7 +1,4 @@
-using System;
-using Castle.DynamicProxy;
-using gorilla.infrastructure.container;
-using gorilla.utility;
+using Castle.DynamicProxy;
 
 namespace solidware.financials.infrastructure
 {
@@ -15,50 +12,4 @@ namespace solidware.financials.infrastructure
             return generator.CreateInterfaceProxyWithTarget(target, interceptors);
         }
     }
-
-    static public class Lazy
-    {
-        static public T load<T>() where T : class
-        {
-            return load(Resolve.the<T>);
-        }
-
-        static public T load<T>(Func<T> get_the_implementation) where T : class
-        {
-            return create_proxy_for<T>(create_interceptor_for(get_the_implementation));
-        }
-
-        static IInterceptor create_interceptor_for<T>(Func<T> get_the_implementation) where T : class
-        {
-            return new LazyLoadedInterceptor<T>(get_the_implementation.memorize());
-        }
-
-        static T create_proxy_for<T>(IInterceptor interceptor) where T : class
-        {
-            return new ProxyGenerator().CreateInterfaceProxyWithoutTarget<T>(interceptor);
-        }
-
-        class LazyLoadedInterceptor<T> : IInterceptor
-        {
-            readonly Func<T> get_the_implementation;
-
-            public LazyLoadedInterceptor(Func<T> get_the_implementation)
-            {
-                this.get_the_implementation = get_the_implementation;
-            }
-
-            public void Intercept(IInvocation invocation)
-            {
-                var method = invocation.GetConcreteMethodInvocationTarget();
-                if( null== method)
-                {
-                    invocation.ReturnValue = invocation.Method.Invoke(get_the_implementation(), invocation.Arguments);
-                }
-                else
-                {
-                    invocation.ReturnValue = method.Invoke(get_the_implementation(), invocation.Arguments);
-                }
-            }
-        }
-    }
 }
\ No newline at end of file
product/infrastructure/infrastructure.csproj
@@ -60,6 +60,7 @@
     <Compile Include="Handles.cs" />
     <Compile Include="InMemoryServiceBus.cs" />
     <Compile Include="IProxyFactory.cs" />
+    <Compile Include="Lazy.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="ServiceBus.cs" />
   </ItemGroup>
product/infrastructure/Lazy.cs
@@ -0,0 +1,53 @@
+using System;
+using Castle.DynamicProxy;
+using gorilla.infrastructure.container;
+using gorilla.utility;
+
+namespace solidware.financials.infrastructure
+{
+    static public class Lazy
+    {
+        static public T load<T>() where T : class
+        {
+            return load(Resolve.the<T>);
+        }
+
+        static public T load<T>(Func<T> get_the_implementation) where T : class
+        {
+            return create_proxy_for<T>(create_interceptor_for(get_the_implementation));
+        }
+
+        static IInterceptor create_interceptor_for<T>(Func<T> get_the_implementation) where T : class
+        {
+            return new LazyLoadedInterceptor<T>(get_the_implementation.memorize());
+        }
+
+        static T create_proxy_for<T>(IInterceptor interceptor) where T : class
+        {
+            return new ProxyGenerator().CreateInterfaceProxyWithoutTarget<T>(interceptor);
+        }
+
+        class LazyLoadedInterceptor<T> : IInterceptor
+        {
+            readonly Func<T> get_the_implementation;
+
+            public LazyLoadedInterceptor(Func<T> get_the_implementation)
+            {
+                this.get_the_implementation = get_the_implementation;
+            }
+
+            public void Intercept(IInvocation invocation)
+            {
+                var method = invocation.GetConcreteMethodInvocationTarget();
+                if( null== method)
+                {
+                    invocation.ReturnValue = invocation.Method.Invoke(get_the_implementation(), invocation.Arguments);
+                }
+                else
+                {
+                    invocation.ReturnValue = method.Invoke(get_the_implementation(), invocation.Arguments);
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
product/service/handlers/AddIncomeCommandMessageHandler.cs
@@ -17,7 +17,9 @@ namespace solidware.financials.service.handlers
 
         public void handle(AddIncomeCommandMessage item)
         {
-            family.find_by(item.PersonId).IncomeAccount().deposit(item.Amount);
+            var person = family.find_by(item.PersonId);
+            person.IncomeAccount().deposit(item.Amount);
+            family.save(person);
             bus.publish<IncomeMessage>(x =>
             {
                 x.Amount = item.Amount;
product/service/orm/ConnectionFactory.cs
@@ -3,5 +3,6 @@
     public interface ConnectionFactory
     {
         Connection Open();
+        Connection Open(string path);
     }
 }
product/service/orm/DB4OConnection.cs
@@ -4,12 +4,14 @@ using System.Collections.Generic;
 using Db4objects.Db4o;
 using Db4objects.Db4o.Ext;
 using Db4objects.Db4o.Query;
+using gorilla.utility;
 
 namespace solidware.financials.service.orm
 {
     public class DB4OConnection : Connection
     {
         readonly IObjectContainer session;
+        Id<long> id = new Id<long>(DateTime.Now.Ticks);
 
         public DB4OConnection(IObjectContainer session)
         {
product/service/orm/DB4OConnectionFactory.cs
@@ -12,11 +12,17 @@ namespace solidware.financials.service.orm
         }
 
         public Connection Open()
+        {
+            ensure_directories_exist();
+            return Open(database_path);
+        }
+
+        public Connection Open(string path)
         {
             if (null == connection)
             {
-                ensure_directories_exist();
                 connection = new DB4OConnection(Db4oFactory.OpenFile(database_path));
+                connection.Ext().Configure().ActivationDepth(int.MaxValue);
                 connection.Ext().Configure().UpdateDepth(int.MaxValue);
             }
             return connection;
product/service/orm/DB4OPersonRepository.cs
@@ -18,7 +18,8 @@ namespace solidware.financials.service.orm
 
         public void save(Person person)
         {
-            person.id = new Id<Guid>(Guid.NewGuid());
+            if(person.id.Equals(Id<Guid>.Default))
+                person.id = new Id<Guid>(Guid.NewGuid());
             session.Store(person);
         }
 
product/specs/unit/infrastructure/ProxyFactorySpecs.cs
@@ -9,7 +9,10 @@ namespace specs.unit.infrastructure
     {
         public class concern
         {
-            Establish context = () => { sut = new CastleProxyFactory(); };
+            Establish context = () =>
+            {
+                sut = new CastleProxyFactory();
+            };
 
             static protected IProxyFactory sut;
         }
@@ -18,17 +21,18 @@ namespace specs.unit.infrastructure
         {
             It should_intercept_calls_made_to_that_class = () =>
             {
-                //
                 interceptor.Intercepted.ShouldBeTrue();
             };
 
             It should_make_the_call_on_the_original_class = () =>
             {
-                //
                 command.result.ShouldEqual("mo");
             };
 
-            Establish context = () => { command = new TestCommand("blah"); };
+            Establish context = () =>
+            {
+                command = new TestCommand("blah");
+            };
 
             Because of = () =>
             {
@@ -43,11 +47,11 @@ namespace specs.unit.infrastructure
 
         public class TestCommand : Command<string>
         {
-            readonly string needAConstructur;
+            readonly string needAConstructor;
 
-            public TestCommand(string needAConstructur)
+            public TestCommand(string needAConstructor)
             {
-                this.needAConstructur = needAConstructur;
+                this.needAConstructor = needAConstructor;
             }
 
             public virtual void run(string item)