Commit d3da9f1

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-24 17:48:26
got the auto wiring working with autofac.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@98 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 6a443a9
trunk/product/MyMoney/boot/container/wire_up_the_container.cs
@@ -1,3 +1,5 @@
+using System;
+using Autofac;
 using MoMoney.boot.container.registration;
 using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.Container.Autofac;
@@ -29,7 +31,8 @@ namespace MoMoney.boot.container
                 .then(new auto_wire_components_in_to_the(registry, specification))
                 .run();
 
-            var dependency_registry = new AutofacDependencyRegistry(registry.build());
+            Func<IContainer> func = registry.build;
+            var dependency_registry = new AutofacDependencyRegistry(func.memorize());
             registry.singleton<IDependencyRegistry>(dependency_registry);
             resolve.initialize_with(dependency_registry);
         }
trunk/product/MyMoney/Infrastructure/Container/Autofac/AutofacDependencyRegistry.cs
@@ -13,21 +13,21 @@ namespace MoMoney.Infrastructure.Container.Autofac
 {
     internal class AutofacDependencyRegistry : IDependencyRegistry
     {
-        readonly IContainer container;
+        readonly Func<IContainer> container;
 
-        public AutofacDependencyRegistry(IContainer container)
+        public AutofacDependencyRegistry(Func<IContainer> container)
         {
             this.container = container;
         }
 
         public Interface get_a<Interface>()
         {
-            return container.Resolve<Interface>();
+            return container().Resolve<Interface>();
         }
 
         public IEnumerable<Interface> all_the<Interface>()
         {
-            return container.Resolve<IEnumerable<Interface>>();
+            return container().Resolve<IEnumerable<Interface>>();
         }
     }
 
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/ComponentExclusionSpecification.cs
@@ -7,10 +7,11 @@ namespace MoMoney.Infrastructure.Container.Windsor.configuration
     {
         public bool is_satisfied_by(Type type)
         {
-            return new NoInterfaces()
-                .or(new SubclassesForm())
-                .or(new ImplementationOfDependencyRegistry())
-                .or(new IsAnEntity())
+            return type.has_no_interfaces()
+                .or(type.subclasses_form())
+                .or(type.is_an_implementation_of_dependency_registry())
+                .or(type.is_an_entity())
+                .or(type.is_an_interface())
                 .is_satisfied_by(type);
         }
     }
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/ComponentExclusionSpecificationSpecs.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Data;
 using System.Windows.Forms;
 using developwithpassion.bdd.contexts;
 using MoMoney.Domain.Core;
@@ -50,6 +51,15 @@ namespace MoMoney.Infrastructure.Container.Windsor.configuration
         static bool result;
     }
 
+    public class when_checking_if_an_interface_should_be_excluded : behaves_like_component_exclusion_specification
+    {
+        it should_be_excluded = () => result.should_be_true();
+
+        because b = () => { result = sut.is_satisfied_by(typeof (IDbConnection)); };
+
+        static bool result;
+    }
+
 
     //public class when_checking_if_a_set_of_observations_should_be_excluded : behaves_like_component_exclusion_specification
     //{
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/ImplementationOfDependencyRegistry.cs
@@ -1,12 +0,0 @@
-using System;
-
-namespace MoMoney.Infrastructure.Container.Windsor.configuration
-{
-    public class ImplementationOfDependencyRegistry : IComponentExclusionSpecification
-    {
-        public bool is_satisfied_by(Type item)
-        {
-            return typeof (IDependencyRegistry).IsAssignableFrom(item);
-        }
-    }
-}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/IsAnEntity.cs
@@ -1,14 +0,0 @@
-using System;
-using MoMoney.Domain.Core;
-using MoMoney.Utility.Core;
-
-namespace MoMoney.Infrastructure.Container.Windsor.configuration
-{
-    public class IsAnEntity : ISpecification<Type>
-    {
-        public bool is_satisfied_by(Type item)
-        {
-            return typeof (IEntity).IsAssignableFrom(item);
-        }
-    }
-}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/NoInterfaces.cs
@@ -1,12 +0,0 @@
-using System;
-
-namespace MoMoney.Infrastructure.Container.Windsor.configuration
-{
-    public class NoInterfaces : IComponentExclusionSpecification
-    {
-        public bool is_satisfied_by(Type item)
-        {
-            return item.GetInterfaces().Length == 0;
-        }
-    }
-}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/SubclassesForm.cs
@@ -1,13 +0,0 @@
-using System;
-using System.Windows.Forms;
-
-namespace MoMoney.Infrastructure.Container.Windsor.configuration
-{
-    public class SubclassesForm : IComponentExclusionSpecification
-    {
-        public bool is_satisfied_by(Type item)
-        {
-            return typeof (Form).IsAssignableFrom(item);
-        }
-    }
-}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/type_extensions.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Windows.Forms;
+using MoMoney.Domain.Core;
+using MoMoney.Utility.Core;
+
+namespace MoMoney.Infrastructure.Container.Windsor.configuration
+{
+    static public class type_extensions
+    {
+        static public ISpecification<Type> has_no_interfaces(this Type item)
+        {
+            return new PredicateSpecification<Type>(x => x.GetInterfaces().Length == 0);
+        }
+
+        static public ISpecification<Type> subclasses_form(this Type item)
+        {
+            return new PredicateSpecification<Type>(x => typeof (Form).IsAssignableFrom(x));
+        }
+
+        static public ISpecification<Type> is_an_implementation_of_dependency_registry(this Type item)
+        {
+            return new PredicateSpecification<Type>(x => typeof (IDependencyRegistry).IsAssignableFrom(x));
+        }
+
+        static public ISpecification<Type> is_an_entity(this Type item)
+        {
+            return new PredicateSpecification<Type>(x => typeof (IEntity).IsAssignableFrom(x));
+        }
+
+        static public ISpecification<Type> is_an_interface(this Type item)
+        {
+            return new PredicateSpecification<Type>(x => x.IsInterface);
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -225,12 +225,9 @@
     </Compile>
     <Compile Include="Infrastructure\Container\Windsor\configuration\ConfigureComponentLifestyle.cs" />
     <Compile Include="Infrastructure\Container\Windsor\configuration\IComponentExclusionSpecification.cs" />
-    <Compile Include="Infrastructure\Container\Windsor\configuration\ImplementationOfDependencyRegistry.cs" />
-    <Compile Include="Infrastructure\Container\Windsor\configuration\IsAnEntity.cs" />
     <Compile Include="Infrastructure\Container\Windsor\configuration\LogComponent.cs" />
-    <Compile Include="Infrastructure\Container\Windsor\configuration\NoInterfaces.cs" />
     <Compile Include="Infrastructure\Container\Windsor\configuration\RegisterComponentContract.cs" />
-    <Compile Include="Infrastructure\Container\Windsor\configuration\SubclassesForm.cs" />
+    <Compile Include="Infrastructure\Container\Windsor\configuration\type_extensions.cs" />
     <Compile Include="Infrastructure\Container\Windsor\IDependencyRegistration.cs" />
     <Compile Include="Infrastructure\Container\Windsor\WindsorContainerFactory.cs" />
     <Compile Include="Infrastructure\debugging\Launch.cs" />