forked from hibernating-rhinos/rhino-esb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
473 additions
and
464 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,89 @@ | ||
using System.Reflection; | ||
using Castle.Core; | ||
using Castle.MicroKernel.Registration; | ||
using Castle.Windsor; | ||
using Rhino.ServiceBus.Actions; | ||
using Rhino.ServiceBus.Hosting; | ||
using Rhino.ServiceBus.Impl; | ||
using Rhino.ServiceBus.Internal; | ||
|
||
namespace Rhino.ServiceBus.Castle | ||
{ | ||
public abstract class CastleBootStrapper : AbstractBootStrapper | ||
{ | ||
private IWindsorContainer container; | ||
|
||
protected CastleBootStrapper() | ||
{ | ||
} | ||
|
||
protected CastleBootStrapper(IWindsorContainer container) | ||
{ | ||
this.container = container; | ||
} | ||
|
||
protected IWindsorContainer Container | ||
{ | ||
get { return container; } | ||
} | ||
|
||
protected override void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration) | ||
{ | ||
configuration.UseCastleWindsor(container); | ||
} | ||
|
||
public override void ExecuteDeploymentActions(string user) | ||
{ | ||
foreach (var action in container.ResolveAll<IDeploymentAction>()) | ||
action.Execute(user); | ||
} | ||
|
||
public override void ExecuteEnvironmentValidationActions() | ||
{ | ||
foreach (var action in container.ResolveAll<IEnvironmentValidationAction>()) | ||
action.Execute(); | ||
} | ||
|
||
public override T GetInstance<T>() | ||
{ | ||
return container.Resolve<T>(); | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
container.Dispose(); | ||
} | ||
|
||
public override void CreateContainer() | ||
{ | ||
if (container == null) | ||
container = new WindsorContainer(); | ||
|
||
ConfigureContainer(); | ||
} | ||
|
||
protected virtual void ConfigureContainer() | ||
{ | ||
foreach (var assembly in Assemblies) | ||
{ | ||
container.Register( | ||
AllTypes.FromAssembly(assembly) | ||
.BasedOn<IDeploymentAction>(), | ||
AllTypes.FromAssembly(assembly) | ||
.BasedOn<IEnvironmentValidationAction>() | ||
); | ||
RegisterConsumersFrom(assembly); | ||
} | ||
} | ||
|
||
protected virtual void RegisterConsumersFrom(Assembly assembly) | ||
{ | ||
container.RegisterConsumersFrom(assembly, ConfigureConsumer); | ||
} | ||
|
||
protected virtual void ConfigureConsumer(ComponentRegistration registration) | ||
{ | ||
registration.Named(registration.Implementation.FullName); | ||
} | ||
} | ||
using System.Reflection; | ||
using Castle.Core; | ||
using Castle.MicroKernel.Registration; | ||
using Castle.Windsor; | ||
using Rhino.ServiceBus.Actions; | ||
using Rhino.ServiceBus.Hosting; | ||
using Rhino.ServiceBus.Impl; | ||
using Rhino.ServiceBus.Internal; | ||
|
||
namespace Rhino.ServiceBus.Castle | ||
{ | ||
public abstract class CastleBootStrapper : AbstractBootStrapper | ||
{ | ||
private IWindsorContainer container; | ||
|
||
protected CastleBootStrapper() | ||
{ | ||
} | ||
|
||
protected CastleBootStrapper(IWindsorContainer container) | ||
{ | ||
this.container = container; | ||
} | ||
|
||
protected IWindsorContainer Container | ||
{ | ||
get { return container; } | ||
} | ||
|
||
protected override void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration) | ||
{ | ||
configuration.UseCastleWindsor(container); | ||
} | ||
|
||
public override void ExecuteDeploymentActions(string user) | ||
{ | ||
foreach (var action in container.ResolveAll<IDeploymentAction>()) | ||
action.Execute(user); | ||
} | ||
|
||
public override void ExecuteEnvironmentValidationActions() | ||
{ | ||
foreach (var action in container.ResolveAll<IEnvironmentValidationAction>()) | ||
action.Execute(); | ||
} | ||
|
||
public override T GetInstance<T>() | ||
{ | ||
return container.Resolve<T>(); | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
container.Dispose(); | ||
} | ||
|
||
public override void CreateContainer() | ||
{ | ||
if (container == null) | ||
container = new WindsorContainer(); | ||
|
||
ConfigureContainer(); | ||
} | ||
|
||
protected virtual void ConfigureContainer() | ||
{ | ||
foreach (var assembly in Assemblies) | ||
{ | ||
container.Register( | ||
AllTypes.FromAssembly(assembly) | ||
.BasedOn<IDeploymentAction>(), | ||
AllTypes.FromAssembly(assembly) | ||
.BasedOn<IEnvironmentValidationAction>() | ||
); | ||
RegisterConsumersFrom(assembly); | ||
} | ||
} | ||
|
||
protected virtual void RegisterConsumersFrom(Assembly assembly) | ||
{ | ||
container.RegisterConsumersFrom(assembly, ConfigureConsumer, IsTypeAcceptableForThisBootStrapper); | ||
} | ||
|
||
protected virtual void ConfigureConsumer(ComponentRegistration registration) | ||
{ | ||
registration.Named(registration.Implementation.FullName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,48 @@ | ||
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); | ||
}) | ||
); | ||
} | ||
} | ||
using System; | ||
using System.Reflection; | ||
using Castle.Core; | ||
using Castle.MicroKernel.Registration; | ||
using Castle.Windsor; | ||
using Rhino.ServiceBus.Castle; | ||
using Rhino.ServiceBus.Impl; | ||
using Rhino.ServiceBus.Internal; | ||
|
||
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), x=>true); | ||
} | ||
|
||
public static void RegisterConsumersFrom(this IWindsorContainer container, Assembly assembly, Action<ComponentRegistration> configureConsumer, Func<Type, bool> isTypeAcceptable) | ||
{ | ||
container.Register( | ||
AllTypes | ||
.FromAssembly(assembly) | ||
.Where(type => | ||
typeof(IMessageConsumer).IsAssignableFrom(type) && | ||
!typeof(IOccasionalMessageConsumer).IsAssignableFrom(type) && | ||
isTypeAcceptable(type) | ||
) | ||
.Configure(registration => | ||
{ | ||
registration.LifeStyle.Is(LifestyleType.Transient); | ||
configureConsumer(registration); | ||
}) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
using System; | ||
using Rhino.ServiceBus.Impl; | ||
using Rhino.ServiceBus.Utils; | ||
using Xunit; | ||
|
||
namespace Rhino.ServiceBus.Tests | ||
{ | ||
public class EndpointRouterTests | ||
{ | ||
|
||
[Fact] | ||
public void can_handle_localhost_consistently() | ||
{ | ||
var router = new EndpointRouter(); | ||
var uri = new Uri("http://localhost/blahdee"); | ||
var normalizedUri = uri.NormalizeLocalhost(); | ||
var routeTo = new Uri("http://remotehost/zippee"); | ||
|
||
router.RemapEndpoint(uri, routeTo); | ||
|
||
Assert.AreEqual(routeTo, router.GetRoutedEndpoint(normalizedUri).Uri); | ||
Assert.AreEqual(routeTo, router.GetRoutedEndpoint(uri).Uri); | ||
} | ||
|
||
[Fact] | ||
public void can_handle_localhost_consistently_2() | ||
{ | ||
var router = new EndpointRouter(); | ||
var uri = new Uri("http://localhost/blahdee"); | ||
var normalizedUri = uri.NormalizeLocalhost(); | ||
var routeFrom = new Uri("http://remotehost/zippee"); | ||
|
||
router.RemapEndpoint(routeFrom, uri); | ||
|
||
Assert.AreEqual(normalizedUri, router.GetRoutedEndpoint(routeFrom).Uri); | ||
} | ||
} | ||
using System; | ||
using Rhino.ServiceBus.Impl; | ||
using Rhino.ServiceBus.Util; | ||
using Xunit; | ||
|
||
namespace Rhino.ServiceBus.Tests | ||
{ | ||
public class EndpointRouterTests | ||
{ | ||
|
||
[Fact] | ||
public void can_handle_localhost_consistently() | ||
{ | ||
var router = new EndpointRouter(); | ||
var uri = new Uri("http://lOcAlHoSt/blahdee"); | ||
var normalizedUri = uri.NormalizeLocalhost(); | ||
var routeTo = new Uri("http://remotehost/zippee"); | ||
|
||
router.RemapEndpoint(uri, routeTo); | ||
|
||
Assert.Equal(routeTo, router.GetRoutedEndpoint(normalizedUri).Uri); | ||
Assert.Equal(routeTo, router.GetRoutedEndpoint(uri).Uri); | ||
} | ||
|
||
[Fact] | ||
public void can_handle_localhost_consistently_2() | ||
{ | ||
var router = new EndpointRouter(); | ||
var uri = new Uri("http://127.0.0.1/blahdee"); | ||
var normalizedUri = uri.NormalizeLocalhost(); | ||
var routeFrom = new Uri("http://remotehost/zippee"); | ||
|
||
router.RemapEndpoint(routeFrom, uri); | ||
|
||
Assert.Equal(normalizedUri, router.GetRoutedEndpoint(routeFrom).Uri); | ||
} | ||
} | ||
} |
Oops, something went wrong.