Skip to content
Browse files

Bug fix and extension method

+ Fix bug in AbstractBootStrapper where ability to provide a config
section (other than the default) was broken.
+ Moved castle consumer registration into an extension method for use
outside the bootstrapper without copy-and-pasting.
  • Loading branch information...
1 parent 56f8c38 commit 214bc57771969792d82495ac3fa5e3e198d3fa95 @mr-miles mr-miles committed with CoreyKaylor
View
15 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)
View
61 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<ComponentRegistration> 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);
+ })
+ );
+ }
+ }
}
View
17 Rhino.ServiceBus.Tests/Hosting/Can_host_in_another_app_domain.cs
@@ -32,6 +32,16 @@ public Can_host_in_another_app_domain()
}
[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()
{
var windsorContainer = new WindsorContainer(new XmlInterpreter());
@@ -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
View
7 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<Assembly> 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)

0 comments on commit 214bc57

Please sign in to comment.
Something went wrong with that request. Please try again.