diff --git a/Rhino.ServiceBus.Castle/CastleBootStrapper.cs b/Rhino.ServiceBus.Castle/CastleBootStrapper.cs index 6f194c6..fad737c 100644 --- a/Rhino.ServiceBus.Castle/CastleBootStrapper.cs +++ b/Rhino.ServiceBus.Castle/CastleBootStrapper.cs @@ -78,20 +78,7 @@ protected virtual void ConfigureContainer() protected virtual void RegisterConsumersFrom(Assembly assembly) { - container.Register( - AllTypes - .FromAssembly(assembly) - .Where(type => - typeof(IMessageConsumer).IsAssignableFrom(type) && - !typeof(IOccasionalMessageConsumer).IsAssignableFrom(type) && - IsTypeAcceptableForThisBootStrapper(type) - ) - .Configure(registration => - { - registration.LifeStyle.Is(LifestyleType.Transient); - ConfigureConsumer(registration); - }) - ); + container.RegisterConsumersFrom(assembly, ConfigureConsumer); } protected virtual void ConfigureConsumer(ComponentRegistration registration) diff --git a/Rhino.ServiceBus.Castle/Extensions.cs b/Rhino.ServiceBus.Castle/Extensions.cs index 428ceaa..a2114fa 100644 --- a/Rhino.ServiceBus.Castle/Extensions.cs +++ b/Rhino.ServiceBus.Castle/Extensions.cs @@ -1,20 +1,43 @@ -using Castle.Windsor; -using Rhino.ServiceBus.Castle; -using Rhino.ServiceBus.Impl; - -namespace Rhino.ServiceBus -{ - public static class Extensions - { - public static AbstractRhinoServiceBusConfiguration UseCastleWindsor(this AbstractRhinoServiceBusConfiguration configuration) - { - return UseCastleWindsor(configuration, new WindsorContainer()); - } - - public static AbstractRhinoServiceBusConfiguration UseCastleWindsor(this AbstractRhinoServiceBusConfiguration configuration, IWindsorContainer container) - { - new CastleBuilder(container, configuration); - return configuration; - } - } +using Castle.Windsor; +using Rhino.ServiceBus.Castle; +using Rhino.ServiceBus.Impl; + +namespace Rhino.ServiceBus +{ + public static class Extensions + { + public static AbstractRhinoServiceBusConfiguration UseCastleWindsor(this AbstractRhinoServiceBusConfiguration configuration) + { + return UseCastleWindsor(configuration, new WindsorContainer()); + } + + public static AbstractRhinoServiceBusConfiguration UseCastleWindsor(this AbstractRhinoServiceBusConfiguration configuration, IWindsorContainer container) + { + new CastleBuilder(container, configuration); + return configuration; + } + + public static void RegisterConsumersFrom(this IWindsorContainer container, Assembly assembly) + { + RegisterConsumersFrom(container, assembly, x=>x.Named(x.Implementation.FullName)); + } + + public static void RegisterConsumersFrom(this IWindsorContainer container, Assembly assembly, Action configureConsumer) + { + container.Register( + AllTypes + .FromAssembly(assembly) + .Where(type => + typeof(IMessageConsumer).IsAssignableFrom(type) && + !typeof(IOccasionalMessageConsumer).IsAssignableFrom(type) && + IsTypeAcceptableForThisBootStrapper(type) + ) + .Configure(registration => + { + registration.LifeStyle.Is(LifestyleType.Transient); + configureConsumer(registration); + }) + ); + } + } } \ No newline at end of file diff --git a/Rhino.ServiceBus.Tests/Hosting/Can_host_in_another_app_domain.cs b/Rhino.ServiceBus.Tests/Hosting/Can_host_in_another_app_domain.cs index 9faa0ec..2c5a4fc 100644 --- a/Rhino.ServiceBus.Tests/Hosting/Can_host_in_another_app_domain.cs +++ b/Rhino.ServiceBus.Tests/Hosting/Can_host_in_another_app_domain.cs @@ -31,6 +31,16 @@ public Can_host_in_another_app_domain() .Configure(); } + [Fact] + public void Can_use_different_config_correctly() + { + var bootStrapper = new SimpleBootStrapper(windsorContainer); + var differentConfig = new BusConfigurationSection(); + bootStrapper.UseConfiguration(differentConfig); + bootStrapper.InitializeContainer(); + Assert.AreEqual(differentConfig, bootStrapper.ConfigurationSectionInUse); + } + [Fact] public void Components_are_registered_using_their_full_name() { @@ -78,10 +88,17 @@ public void Consume(StringMsg message) public class SimpleBootStrapper : CastleBootStrapper { + public BusConfigurationSection ConfigurationSectionInUse {get ; private set;} + public SimpleBootStrapper(IWindsorContainer container) : base(container) { } + + protected override void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration) + { + ConfigurationSectionInUse = configuration.ConfigurationSection; + } } public class TestBootStrapper : CastleBootStrapper diff --git a/Rhino.ServiceBus/Hosting/AbstractBootStrapper.cs b/Rhino.ServiceBus/Hosting/AbstractBootStrapper.cs index 4a788aa..e07bada 100644 --- a/Rhino.ServiceBus/Hosting/AbstractBootStrapper.cs +++ b/Rhino.ServiceBus/Hosting/AbstractBootStrapper.cs @@ -9,6 +9,7 @@ namespace Rhino.ServiceBus.Hosting public abstract class AbstractBootStrapper : IDisposable { private AbstractRhinoServiceBusConfiguration config; + private BusConfigurationSection busSection; public virtual IEnumerable Assemblies { @@ -24,7 +25,7 @@ public virtual void InitializeContainer() public virtual void UseConfiguration(BusConfigurationSection configurationSection) { - config.UseConfiguration(configurationSection); + busSection = configurationSection; } public abstract void CreateContainer(); @@ -42,7 +43,9 @@ protected virtual bool IsTypeAcceptableForThisBootStrapper(Type t) protected virtual AbstractRhinoServiceBusConfiguration CreateConfiguration() { - return new RhinoServiceBusConfiguration(); + var cfg = new RhinoServiceBusConfiguration(); + if (busSection!=null) config.UseConfiguration(configurationSection); + return cfg; } protected virtual void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration)