Commit 977c48c

mo <email@solidware.ca>
2011-03-20 05:06:57
hooked up unit of work intercept around handlers.
1 parent b58b772
product/desktop.ui/bootstrappers/AutofacExtensions.cs
@@ -0,0 +1,20 @@
+using Autofac;
+using Autofac.Builder;
+using Castle.DynamicProxy;
+using solidware.financials.infrastructure;
+
+namespace solidware.financials.windows.ui.bootstrappers
+{
+    static public class AutofacExtensions
+    {
+        static readonly IProxyFactory factory = new CastleProxyFactory();
+
+        static public IRegistrationBuilder<Interface, SimpleActivatorData, SingleRegistrationStyle> RegisterProxy
+            <Interface, Implementation>(
+            this ContainerBuilder builder, params IInterceptor[] interceptors) where Implementation : Interface where Interface : class
+        {
+            builder.RegisterType<Implementation>();
+            return builder.Register(x => factory.CreateProxyFor<Interface>(x.Resolve<Implementation>(), interceptors)).As<Interface>();
+        }
+    }
+}
\ No newline at end of file
product/desktop.ui/bootstrappers/Bootstrapper.cs
@@ -18,9 +18,9 @@ using solidware.financials.windows.ui.views;
 
 namespace solidware.financials.windows.ui.bootstrappers
 {
-    public static class Bootstrapper
+    static public class Bootstrapper
     {
-        public static ShellWindow create_window()
+        static public ShellWindow create_window()
         {
             var builder = new ContainerBuilder();
 
@@ -35,7 +35,7 @@ namespace solidware.financials.windows.ui.bootstrappers
             builder.RegisterType<DefaultMapper>().As<Mapper>().SingleInstance();
             //builder.RegisterGeneric(typeof (Mapper<,>));
             builder.RegisterType<InMemoryServiceBus>().As<ServiceBus>().SingleInstance();
-            builder.RegisterGeneric(typeof(IfFamilyMemberIsSelected<>));
+            builder.RegisterGeneric(typeof (IfFamilyMemberIsSelected<>));
 
             register_presentation_infrastructure(builder);
             register_presenters(builder);
@@ -56,7 +56,6 @@ namespace solidware.financials.windows.ui.bootstrappers
             builder.RegisterType<ComposeShell>().As<NeedStartup>();
             builder.RegisterType<ConfigureMappings>().As<NeedStartup>();
             builder.RegisterType<WireUpSubscribers>().As<NeedStartup>();
-            new DB4OBootstrapper().run();
         }
 
         static void register_presentation_infrastructure(ContainerBuilder builder)
@@ -89,7 +88,7 @@ namespace solidware.financials.windows.ui.bootstrappers
             builder.RegisterType<IfFamilyMemberIsSelected<AddNewIncomeViewModel>>();
 
             builder.RegisterType<TaxSummaryPresenter>();
-            
+
             builder.RegisterType<DisplayCanadianTaxInformationViewModel>();
         }
 
@@ -97,14 +96,15 @@ namespace solidware.financials.windows.ui.bootstrappers
         {
             builder.RegisterType<PublishEventHandler<AddedNewFamilyMember>>().As<Handles<AddedNewFamilyMember>>();
             builder.RegisterType<PublishEventHandler<AddIncomeCommandMessage>>().As<Handles<AddIncomeCommandMessage>>();
-            
         }
 
         static void server_registration(ContainerBuilder builder)
         {
-            builder.RegisterType<AddNewFamilyMemberHandler>().As<Handles<FamilyMemberToAdd>>();
-            builder.RegisterType<FindAllFamilyHandler>().As<Handles<FindAllFamily>>();
+            var interceptor = new UnitOfWorkInterceptor();
+            builder.RegisterProxy<Handles<FamilyMemberToAdd>, AddNewFamilyMemberHandler>(interceptor);
+            builder.RegisterProxy<Handles<FindAllFamily>, FindAllFamilyHandler>(interceptor);
             builder.RegisterType<InMemoryDatabase>().As<PersonRepository>().SingleInstance();
+            new DB4OBootstrapper().run();
         }
     }
 }
\ No newline at end of file
product/desktop.ui/solidware.financials.csproj
@@ -60,6 +60,7 @@
     <Reference Include="Autofac">
       <HintPath>..\..\thirdparty\autofac\Autofac.dll</HintPath>
     </Reference>
+    <Reference Include="Castle.Core, Version=2.5.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL" />
     <Reference Include="gorilla.infrastructure">
       <HintPath>..\..\thirdparty\commons\gorilla.infrastructure.dll</HintPath>
     </Reference>
@@ -85,6 +86,7 @@
   <ItemGroup>
     <Compile Include="ApplicationController.cs" />
     <Compile Include="bootstrappers\AutofacDependencyRegistry.cs" />
+    <Compile Include="bootstrappers\AutofacExtensions.cs" />
     <Compile Include="bootstrappers\Bootstrapper.cs" />
     <Compile Include="bootstrappers\ComposeShell.cs" />
     <Compile Include="bootstrappers\ConfigureMappings.cs" />
product/infrastructure/CastleProxyFactory.cs
@@ -6,9 +6,9 @@ namespace solidware.financials.infrastructure
     {
         ProxyGenerator generator = new ProxyGenerator();
 
-        public Proxy CreateProxyFor<Proxy>(Proxy clazz, params IInterceptor[] interceptors) where Proxy : class
+        public Interface CreateProxyFor<Interface>(Interface target, params IInterceptor[] interceptors) where Interface : class
         {
-            return generator.CreateClassProxyWithTarget(clazz, interceptors);
+            return generator.CreateInterfaceProxyWithTarget(target, interceptors);
         }
     }
 }
\ No newline at end of file
product/infrastructure/IProxyFactory.cs
@@ -4,6 +4,6 @@ namespace solidware.financials.infrastructure
 {
     public interface IProxyFactory
     {
-        T CreateProxyFor<T>(T clazz, params IInterceptor[] interceptors) where T : class;
+        T CreateProxyFor<T>(T target, params IInterceptor[] interceptors) where T : class;
     }
 }
\ No newline at end of file
product/service/orm/DB4ODatabase.cs → product/service/orm/DB4OPersonRepository.cs
@@ -6,11 +6,11 @@ using solidware.financials.service.domain;
 
 namespace solidware.financials.service.orm
 {
-    public class DB4ODatabase : PersonRepository
+    public class DB4OPersonRepository : PersonRepository
     {
         IObjectContainer session;
 
-        public DB4ODatabase(IObjectContainer session)
+        public DB4OPersonRepository(IObjectContainer session)
         {
             this.session = session;
         }
product/service/orm/UnitOfWorkInterceptor.cs
@@ -0,0 +1,12 @@
+using Castle.DynamicProxy;
+
+namespace solidware.financials.service.orm
+{
+    public class UnitOfWorkInterceptor : IInterceptor
+    {
+        public void Intercept(IInvocation invocation)
+        {
+            invocation.Proceed();
+        }
+    }
+}
\ No newline at end of file
product/service/service.csproj
@@ -31,6 +31,7 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Castle.Core, Version=2.5.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL" />
     <Reference Include="Db4objects.Db4o">
       <HintPath>..\..\thirdparty\db4o\Db4objects.Db4o.dll</HintPath>
     </Reference>
@@ -56,10 +57,11 @@
     <Compile Include="domain\Entity.cs" />
     <Compile Include="domain\Person.cs" />
     <Compile Include="handlers\FindAllFamilyHandler.cs" />
-    <Compile Include="orm\DB4ODatabase.cs" />
+    <Compile Include="orm\DB4OPersonRepository.cs" />
     <Compile Include="orm\InMemoryDatabase.cs" />
     <Compile Include="orm\LastOpened.cs" />
     <Compile Include="orm\PersonRepository.cs" />
+    <Compile Include="orm\UnitOfWorkInterceptor.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
product/specs/unit/infrastructure/ProxyFactorySpecs.cs
@@ -28,12 +28,12 @@ namespace specs.unit.infrastructure
                 command.result.ShouldEqual("mo");
             };
 
-            Establish context = () => { command = new TestCommand(); };
+            Establish context = () => { command = new TestCommand("blah"); };
 
             Because of = () =>
             {
                 interceptor = new TestInterceptor();
-                var proxy = sut.CreateProxyFor(command, interceptor);
+                var proxy = sut.CreateProxyFor<Command<string>>(command, interceptor);
                 proxy.run("mo");
             };
 
@@ -43,6 +43,13 @@ namespace specs.unit.infrastructure
 
         public class TestCommand : Command<string>
         {
+            readonly string needAConstructur;
+
+            public TestCommand(string needAConstructur)
+            {
+                this.needAConstructur = needAConstructur;
+            }
+
             public virtual void run(string item)
             {
                 result = item;
.gitignore
@@ -10,3 +10,4 @@ local.properties.xml
 %APPDATA%
 app.config
 *.stackdump
+AssemblyInfo.cs