Commit 68aae8a
Changed files (19)
trunk
src
MyMoney
Domain
Core
Infrastructure
Container
Windsor
configuration
Logging
Utility
trunk/src/MyMoney/Domain/Core/IRepository.cs
@@ -1,8 +1,9 @@
using System.Collections.Generic;
+using MyMoney.Infrastructure.Logging;
namespace MyMoney.Domain.Core
{
- public interface IRepository
+ public interface IRepository : ILoggable
{
IEnumerable<T> all<T>() where T : IEntity;
void save<T>(T item) where T : IEntity;
trunk/src/MyMoney/Infrastructure/Container/Windsor/configuration/ApplyLoggingInterceptor.cs
@@ -0,0 +1,22 @@
+using Castle.Core;
+using Castle.MicroKernel.Registration;
+using MyMoney.Infrastructure.interceptors;
+using MyMoney.Infrastructure.Logging;
+
+namespace MyMoney.Infrastructure.Container.Windsor.configuration
+{
+ public class ApplyLoggingInterceptor : IRegistrationConfiguration
+ {
+ public void configure(ComponentRegistration registration)
+ {
+ var implementation = registration.Implementation;
+ if (typeof (ILoggable).IsAssignableFrom(implementation))
+ {
+ registration
+ .Interceptors(new InterceptorReference(typeof (ILoggingInterceptor)))
+ .First
+ .If((k, m) => true);
+ }
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Container/Windsor/configuration/component_exclusion_specification.cs
@@ -0,0 +1,18 @@
+using System;
+using MyMoney.Utility.Extensions;
+
+namespace MyMoney.Infrastructure.Container.Windsor.configuration
+{
+ public class component_exclusion_specification : IComponentExclusionSpecification
+ {
+ public bool is_satisfied_by(Type type)
+ {
+ return
+ new NoInterfaces()
+ .or(new SubclassesForm())
+ .or(new ImplementationOfDependencyRegistry())
+ .is_satisfied_by(type);
+ //return type.GetInterfaces().Length == 0 || type.IsSubclassOf(typeof (Form)) || type.IsAssignableFrom(typeof (IDependencyRegistry));
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Container/Windsor/configuration/component_registration_configuration.cs
@@ -0,0 +1,20 @@
+using Castle.MicroKernel.Registration;
+using MyMoney.Utility.Core;
+using MyMoney.Utility.Extensions;
+
+namespace MyMoney.Infrastructure.Container.Windsor.configuration
+{
+ public interface IRegistrationConfiguration : IConfiguration<ComponentRegistration>
+ {
+ }
+
+ public class component_registration_configuration : IRegistrationConfiguration
+ {
+ public void configure(ComponentRegistration registration)
+ {
+ new RegisterComponentContract()
+ .then(new ApplyLoggingInterceptor())
+ .configure(registration);
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Container/Windsor/configuration/IComponentExclusionSpecification.cs
@@ -0,0 +1,9 @@
+using System;
+using MyMoney.Utility.Core;
+
+namespace MyMoney.Infrastructure.Container.Windsor.configuration
+{
+ public interface IComponentExclusionSpecification : ISpecification<Type>
+ {
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Container/Windsor/configuration/ImplementationOfDependencyRegistry.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace MyMoney.Infrastructure.Container.Windsor.configuration
+{
+ public class ImplementationOfDependencyRegistry : IComponentExclusionSpecification
+ {
+ public bool is_satisfied_by(Type item)
+ {
+ return item.IsAssignableFrom(typeof (IDependencyRegistry));
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Container/Windsor/configuration/NoInterfaces.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace MyMoney.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/src/MyMoney/Infrastructure/Container/Windsor/configuration/RegisterComponentContract.cs
@@ -0,0 +1,25 @@
+using Castle.Core;
+using Castle.MicroKernel.Registration;
+
+namespace MyMoney.Infrastructure.Container.Windsor.configuration
+{
+ public class RegisterComponentContract : IRegistrationConfiguration
+ {
+ public void configure(ComponentRegistration registration)
+ {
+ var implementation = registration.Implementation;
+ if (implementation.GetInterfaces().Length == 0)
+ {
+ registration.For(implementation);
+ }
+ else
+ {
+ if (implementation.GetCustomAttributes(typeof (SingletonAttribute), false).Length > 0)
+ {
+ registration.LifeStyle.Is(LifestyleType.Singleton);
+ }
+ registration.LifeStyle.Is(LifestyleType.Transient);
+ }
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Container/Windsor/configuration/SubclassesForm.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Windows.Forms;
+
+namespace MyMoney.Infrastructure.Container.Windsor.configuration
+{
+ public class SubclassesForm : IComponentExclusionSpecification
+ {
+ public bool is_satisfied_by(Type item)
+ {
+ return item.IsSubclassOf(typeof (Form));
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Container/Windsor/component_exclusion_specification.cs
@@ -1,19 +0,0 @@
-using System;
-using System.Windows.Forms;
-using MyMoney.Utility.Core;
-
-namespace MyMoney.Infrastructure.Container.Windsor
-{
- public interface IComponentExclusionSpecification : ISpecification<Type>
- {}
-
- public class component_exclusion_specification : IComponentExclusionSpecification
- {
- public bool is_satisfied_by(Type type)
- {
- return type.GetInterfaces().Length == 0
- || type.IsSubclassOf(typeof (Form))
- || type.IsAssignableFrom(typeof (IDependencyRegistry));
- }
- }
-}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Container/Windsor/component_registration_configuration.cs
@@ -1,36 +0,0 @@
-using Castle.Core;
-using Castle.MicroKernel.Registration;
-using MyMoney.Domain.Core;
-using MyMoney.Infrastructure.interceptors;
-
-namespace MyMoney.Infrastructure.Container.Windsor
-{
- public interface IRegistrationConfiguration
- {
- void configure(ComponentRegistration registration);
- }
-
- public class component_registration_configuration : IRegistrationConfiguration
- {
- public void configure(ComponentRegistration registration)
- {
- var implementation = registration.Implementation;
- if (implementation.GetInterfaces().Length == 0) {
- registration.For(implementation);
- }
- else {
- if (implementation.GetCustomAttributes(typeof (SingletonAttribute), false).Length > 0) {
- registration.LifeStyle.Is(LifestyleType.Singleton);
- }
- registration.LifeStyle.Is(LifestyleType.Transient);
- }
-
- if (typeof (IRepository).IsAssignableFrom(implementation)) {
- registration
- .Interceptors(new InterceptorReference(typeof (ILoggingInterceptor)))
- .First
- .If((k, m) => true);
- }
- }
- }
-}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Container/Windsor/windsor_container_factory.cs
@@ -1,22 +1,25 @@
using Castle.MicroKernel.Registration;
using Castle.Windsor;
+using MyMoney.Infrastructure.Container.Windsor.configuration;
using MyMoney.Utility.Core;
namespace MyMoney.Infrastructure.Container.Windsor
{
public interface IWindsorContainerFactory : IFactory<IWindsorContainer>
- {}
+ {
+ }
public class windsor_container_factory : IWindsorContainerFactory
{
- private static IWindsorContainer container;
- private static readonly object mutex = new object();
- private readonly IComponentExclusionSpecification criteria_to_satisfy;
- private readonly IRegistrationConfiguration configuration;
+ static IWindsorContainer container;
+ static readonly object mutex = new object();
+ readonly IComponentExclusionSpecification criteria_to_satisfy;
+ readonly IRegistrationConfiguration configuration;
public windsor_container_factory()
: this(new component_exclusion_specification(), new component_registration_configuration())
- {}
+ {
+ }
public windsor_container_factory(IComponentExclusionSpecification criteria_to_satisfy,
IRegistrationConfiguration configuration)
@@ -27,9 +30,12 @@ namespace MyMoney.Infrastructure.Container.Windsor
public IWindsorContainer create()
{
- if (null == container) {
- lock (mutex) {
- if (null == container) {
+ if (null == container)
+ {
+ lock (mutex)
+ {
+ if (null == container)
+ {
container = register_components_into_container();
}
}
@@ -37,7 +43,7 @@ namespace MyMoney.Infrastructure.Container.Windsor
return container;
}
- private IWindsorContainer register_components_into_container()
+ IWindsorContainer register_components_into_container()
{
var the_container = new WindsorContainer();
the_container.Register(
trunk/src/MyMoney/Infrastructure/Logging/ILoggable.cs
@@ -0,0 +1,7 @@
+namespace MyMoney.Infrastructure.Logging
+{
+ public interface ILoggable
+ {
+
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Utility/Core/and_specification.cs
@@ -2,8 +2,8 @@ namespace MyMoney.Utility.Core
{
public class and_specification<T> : ISpecification<T>
{
- private readonly ISpecification<T> left;
- private readonly ISpecification<T> right;
+ readonly ISpecification<T> left;
+ readonly ISpecification<T> right;
public and_specification(ISpecification<T> left, ISpecification<T> right)
{
trunk/src/MyMoney/Utility/Core/ChainedConfiguration.cs
@@ -0,0 +1,20 @@
+namespace MyMoney.Utility.Core
+{
+ public class ChainedConfiguration<T> : IConfiguration<T>
+ {
+ readonly IConfiguration<T> first;
+ readonly IConfiguration<T> second;
+
+ public ChainedConfiguration(IConfiguration<T> first, IConfiguration<T> second)
+ {
+ this.first = first;
+ this.second = second;
+ }
+
+ public void configure(T item)
+ {
+ first.configure(item);
+ second.configure(item);
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Utility/Core/IConfiguration.cs
@@ -0,0 +1,7 @@
+namespace MyMoney.Utility.Core
+{
+ public interface IConfiguration<T>
+ {
+ void configure(T item);
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Utility/Core/or_specification.cs
@@ -2,8 +2,8 @@ namespace MyMoney.Utility.Core
{
public class or_specification<T> : ISpecification<T>
{
- private readonly ISpecification<T> left;
- private readonly ISpecification<T> right;
+ readonly ISpecification<T> left;
+ readonly ISpecification<T> right;
public or_specification(ISpecification<T> left, ISpecification<T> right)
{
trunk/src/MyMoney/Utility/Extensions/configuration_extensions.cs
@@ -0,0 +1,12 @@
+using MyMoney.Utility.Core;
+
+namespace MyMoney.Utility.Extensions
+{
+ public static class configuration_extensions
+ {
+ public static IConfiguration<T> then<T>(this IConfiguration<T> first, IConfiguration<T> second)
+ {
+ return new ChainedConfiguration<T>(first, second);
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/MyMoney.csproj
@@ -190,7 +190,13 @@
<Compile Include="Domain\Core\range.cs" />
<Compile Include="Domain\Core\range_specs.cs" />
<Compile Include="Domain\repositories\company_repository_extensions.cs" />
- <Compile Include="Infrastructure\Container\Windsor\component_exclusion_specification.cs" />
+ <Compile Include="Infrastructure\Container\Windsor\configuration\ApplyLoggingInterceptor.cs" />
+ <Compile Include="Infrastructure\Container\Windsor\configuration\component_exclusion_specification.cs" />
+ <Compile Include="Infrastructure\Container\Windsor\configuration\IComponentExclusionSpecification.cs" />
+ <Compile Include="Infrastructure\Container\Windsor\configuration\ImplementationOfDependencyRegistry.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\windsor_container_factory.cs" />
<Compile Include="Infrastructure\eventing\event_aggregator.cs" />
<Compile Include="Infrastructure\eventing\IEvent.cs" />
@@ -202,6 +208,7 @@
<Compile Include="Infrastructure\interceptors\logging_interceptor.cs" />
<Compile Include="Infrastructure\interceptors\raise_event_interceptor.cs" />
<Compile Include="Infrastructure\interceptors\unit_of_work_interceptor.cs" />
+ <Compile Include="Infrastructure\Logging\ILoggable.cs" />
<Compile Include="Infrastructure\registries\default_registry.cs" />
<Compile Include="Infrastructure\registries\default_registry_specs.cs" />
<Compile Include="Domain\accounting\billing\Bill.cs" />
@@ -214,7 +221,7 @@
<Compile Include="Domain\Core\Month.cs" />
<Compile Include="Domain\Core\Months.cs" />
<Compile Include="Domain\Core\registry_extensions.cs" />
- <Compile Include="Infrastructure\Container\Windsor\component_registration_configuration.cs" />
+ <Compile Include="Infrastructure\Container\Windsor\configuration\component_registration_configuration.cs" />
<Compile Include="Infrastructure\System\application_environment.cs" />
<Compile Include="Infrastructure\Threading\background_thread_factory.cs" />
<Compile Include="Infrastructure\Threading\background_thread.cs">
@@ -425,12 +432,14 @@
<Compile Include="Testing\spechelpers\core\IHideObjectMembers.cs" />
<Compile Include="Testing\spechelpers\core\method_call_occurance.cs" />
<Compile Include="Testing\MetaData\run_in_real_container.cs" />
+ <Compile Include="Utility\Core\ChainedConfiguration.cs" />
<Compile Include="Utility\Core\chained_mapper.cs" />
<Compile Include="Utility\Core\and_specification.cs" />
<Compile Include="Utility\Core\command.cs" />
<Compile Include="Utility\Core\empty_command.cs" />
<Compile Include="Utility\Core\IBuilder.cs" />
<Compile Include="Utility\Core\ICallback.cs" />
+ <Compile Include="Utility\Core\IConfiguration.cs" />
<Compile Include="Utility\Core\IDisposableCommand.cs" />
<Compile Include="Utility\Core\IFactory.cs" />
<Compile Include="Utility\Core\IParameterizedCommand.cs" />
@@ -469,6 +478,7 @@
<Compile Include="Utility\Core\ISpecification.cs" />
<Compile Include="Utility\Core\Map.cs" />
<Compile Include="Utility\Core\or_specification.cs" />
+ <Compile Include="Utility\Extensions\configuration_extensions.cs" />
<Compile Include="Utility\Extensions\conversion_extensions.cs" />
<Compile Include="Utility\Extensions\enumerable_extensions.cs" />
<Compile Include="Utility\Extensions\func_extensions.cs" />