Permalink
Browse files

final decoupling

  • Loading branch information...
1 parent 755f854 commit 360a88f04a6c1a9990e370c84b8e718916697ffc Sky Morey committed Sep 3, 2012
Showing with 1,835 additions and 1,592 deletions.
  1. +136 −102 Rhino.ServiceBus.Autofac/AutofacBuilder.cs
  2. +43 −43 Rhino.ServiceBus.Autofac/AutofacServiceLocator.cs
  3. +0 −7 Rhino.ServiceBus.Autofac/Rhino.ServiceBus.Autofac.csproj
  4. +161 −149 Rhino.ServiceBus.Castle/CastleBuilder.cs
  5. +0 −7 Rhino.ServiceBus.Castle/Rhino.ServiceBus.Castle.csproj
  6. +0 −10 Rhino.ServiceBus.RhinoQueues/Config/IRhinoQueuesBusContainerBuilder.cs
  7. +33 −9 Rhino.ServiceBus.RhinoQueues/Config/RhinoQueuesConfigurationAware.cs
  8. +0 −30 Rhino.ServiceBus.RhinoQueues/Config/RhinoQueuesOneWayBusConfiguration.cs
  9. +46 −0 Rhino.ServiceBus.RhinoQueues/Config/RhinoQueuesOneWayBusConfigurationAware.cs
  10. +1 −2 Rhino.ServiceBus.RhinoQueues/Rhino.ServiceBus.RhinoQueues.csproj
  11. +36 −38 Rhino.ServiceBus.Spring/ConsumerInterceptor.cs
  12. +0 −8 Rhino.ServiceBus.Spring/Rhino.ServiceBus.Spring.csproj
  13. +262 −247 Rhino.ServiceBus.Spring/SpringBuilder.cs
  14. +33 −33 Rhino.ServiceBus.StructureMap/ConsumerInterceptor.cs
  15. +0 −7 Rhino.ServiceBus.StructureMap/Rhino.ServiceBus.StructureMap.csproj
  16. +269 −236 Rhino.ServiceBus.StructureMap/StructureMapBuilder.cs
  17. +134 −107 Rhino.ServiceBus.Tests/Containers/Autofac/ContainerTests.cs
  18. +32 −2 Rhino.ServiceBus.Tests/Containers/Castle/ContainerTests.cs
  19. +32 −3 Rhino.ServiceBus.Tests/Containers/StructureMap/ContainerTests.cs
  20. +13 −13 Rhino.ServiceBus.Tests/Containers/Unity/ContainerTests.cs
  21. +35 −35 Rhino.ServiceBus.Unity/ConsumerExtension.cs
  22. +26 −30 Rhino.ServiceBus.Unity/ContainerExtensions.cs
  23. +0 −8 Rhino.ServiceBus.Unity/Rhino.ServiceBus.Unity.csproj
  24. +312 −294 Rhino.ServiceBus.Unity/UnityBuilder.cs
  25. +2 −1 Rhino.ServiceBus/Config/IBusConfigurationAware.cs
  26. +24 −19 Rhino.ServiceBus/Config/IBusContainerBuilder.cs
  27. +23 −27 Rhino.ServiceBus/Config/{LoadBalancerConfiguration.cs → LoadBalancerConfigurationAware.cs}
  28. +36 −40 ...viceBus/Config/{LoadBalancerEndpointConfiguration.cs → LoadBalancerEndpointConfigurationAware.cs}
  29. +29 −30 Rhino.ServiceBus/Config/{LoggingConfiguration.cs → LoggingConfigurationAware.cs}
  30. +61 −18 Rhino.ServiceBus/Config/MsmqTransportConfigurationAware.cs
  31. +0 −26 Rhino.ServiceBus/Config/OneWayBusConfiguration.cs
  32. +42 −0 Rhino.ServiceBus/Config/OneWayBusConfigurationAware.cs
  33. +5 −4 Rhino.ServiceBus/Config/{SecurityConfiguration.cs → SecurityConfigurationAware.cs}
  34. +0 −2 Rhino.ServiceBus/Hosting/AbstractBootStrapper.cs
  35. +5 −5 Rhino.ServiceBus/Rhino.ServiceBus.csproj
  36. +4 −0 Samples/Starbucks/Starbucks.csproj
@@ -1,27 +1,25 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Messaging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Messaging;
using Autofac;
-using Rhino.Queues;
-using Rhino.ServiceBus.Actions;
-using Rhino.ServiceBus.Config;
-using Rhino.ServiceBus.Convertors;
-using Rhino.ServiceBus.DataStructures;
-using Rhino.ServiceBus.Impl;
-using Rhino.ServiceBus.Internal;
-using Rhino.ServiceBus.LoadBalancer;
-using Rhino.ServiceBus.MessageModules;
-using Rhino.ServiceBus.Msmq;
-using Rhino.ServiceBus.Msmq.TransportActions;
-using Rhino.ServiceBus.RhinoQueues;
-using ErrorAction = Rhino.ServiceBus.Msmq.TransportActions.ErrorAction;
+using Rhino.ServiceBus.Actions;
+using Rhino.ServiceBus.Config;
+using Rhino.ServiceBus.Convertors;
+using Rhino.ServiceBus.DataStructures;
+using Rhino.ServiceBus.Impl;
+using Rhino.ServiceBus.Internal;
+using Rhino.ServiceBus.LoadBalancer;
+using Rhino.ServiceBus.MessageModules;
+using Rhino.ServiceBus.Msmq;
+using Rhino.ServiceBus.Msmq.TransportActions;
+using ErrorAction = Rhino.ServiceBus.Msmq.TransportActions.ErrorAction;
using LoadBalancerConfiguration = Rhino.ServiceBus.LoadBalancer.LoadBalancerConfiguration;
-using System.Reflection;
-
-namespace Rhino.ServiceBus.Autofac
+using System.Reflection;
+
+namespace Rhino.ServiceBus.Autofac
{
- public class AutofacBuilder : IBusContainerBuilder, IRhinoQueuesBusContainerBuilder
+ public class AutofacBuilder : IBusContainerBuilder
{
private readonly AbstractRhinoServiceBusConfiguration config;
private readonly IContainer container;
@@ -61,7 +59,7 @@ public void RegisterDefaultServices(IEnumerable<Assembly> assemblies)
builder.RegisterType<EndpointRouter>()
.As<IEndpointRouter>()
.SingleInstance();
- foreach(var module in config.MessageModules)
+ foreach (var module in config.MessageModules)
{
builder.RegisterType(module)
.Named<string>(module.FullName)
@@ -70,8 +68,9 @@ public void RegisterDefaultServices(IEnumerable<Assembly> assemblies)
}
builder.Update(container);
- foreach(var busConfigurationAware in container.Resolve<IEnumerable<IBusConfigurationAware>>())
- busConfigurationAware.Configure(config, this);
+ var locator = container.Resolve<IServiceLocator>();
+ foreach (var busConfigurationAware in container.Resolve<IEnumerable<IBusConfigurationAware>>())
+ busConfigurationAware.Configure(config, this, locator);
}
public void RegisterBus()
@@ -165,101 +164,136 @@ public void RegisterLoggingEndpoint(Uri logEndpoint)
builder.Update(container);
}
- public void RegisterMsmqTransport(Type queueStrategyType)
+ public void RegisterSingleton<T>(Func<T> func)
+ where T : class
{
+ T singleton = null;
var builder = new ContainerBuilder();
- builder.RegisterType(queueStrategyType)
- .WithParameter("endpoint", config.Endpoint)
- .As<IQueueStrategy>()
- .SingleInstance();
- builder.RegisterType<MsmqMessageBuilder>()
- .As<IMessageBuilder<Message>>()
- .SingleInstance();
- builder.RegisterType<ErrorAction>()
- .WithParameter("numberOfRetries", config.NumberOfRetries)
- .As<IMsmqTransportAction>()
- .SingleInstance();
- builder.RegisterType<MsmqSubscriptionStorage>()
- .WithParameter("queueBusListensTo", config.Endpoint)
- .As<ISubscriptionStorage>()
- .SingleInstance();
- builder.RegisterType<MsmqTransport>()
- .WithParameter("endpoint", config.Endpoint)
- .WithParameter("threadCount", config.ThreadCount)
- .WithParameter("queueIsolationLevel", config.IsolationLevel)
- .WithParameter("transactional", config.Transactional)
- .WithParameter("consumeInTransaction", config.ConsumeInTransaction)
- .As<ITransport>()
- .SingleInstance();
- builder.RegisterAssemblyTypes(typeof(IMsmqTransportAction).Assembly)
- .Where(x => typeof(IMsmqTransportAction).IsAssignableFrom(x) && x != typeof(ErrorAction))
- .As<IMsmqTransportAction>()
+ builder.Register(x => singleton == null ? singleton = func() : singleton)
+ .As<T>()
.SingleInstance();
builder.Update(container);
}
-
- public void RegisterQueueCreation()
+ public void RegisterSingleton<T>(string name, Func<T> func)
+ where T : class
{
+ T singleton = null;
var builder = new ContainerBuilder();
- builder.RegisterType<QueueCreationModule>()
- .As<IServiceBusAware>()
+ builder.Register(x => singleton == null ? singleton = func() : singleton)
+ .As<T>()
+ .Named<T>(name)
.SingleInstance();
builder.Update(container);
}
- public void RegisterMsmqOneWay()
+ public void RegisterAll<T>(params Type[] excludes)
+ where T : class { RegisterAll<T>((Predicate<Type>)(x => !x.IsAbstract && !x.IsInterface && typeof(T).IsAssignableFrom(x) && !excludes.Contains(x))); }
+ public void RegisterAll<T>(Predicate<Type> condition)
+ where T : class
{
var builder = new ContainerBuilder();
- var oneWayConfig = (OnewayRhinoServiceBusConfiguration)config;
- builder.RegisterType<MsmqMessageBuilder>()
- .As<IMessageBuilder<Message>>()
- .SingleInstance();
- builder.RegisterType<MsmqOnewayBus>()
- .WithParameter("messageOwners", oneWayConfig.MessageOwners)
- .As<IOnewayBus>()
+ builder.RegisterAssemblyTypes(typeof(T).Assembly)
+ .Where(x => condition(x))
+ .As<T>()
.SingleInstance();
builder.Update(container);
}
- public void RegisterRhinoQueuesTransport()
- {
- var busConfig = config.ConfigurationSection.Bus;
- var builder = new ContainerBuilder();
- builder.RegisterType<PhtSubscriptionStorage>()
- .WithParameter("subscriptionPath", busConfig.SubscriptionPath)
- .As<ISubscriptionStorage>()
- .SingleInstance();
- builder.RegisterType<RhinoQueuesTransport>()
- .WithParameter("threadCount", config.ThreadCount)
- .WithParameter("endpoint", config.Endpoint)
- .WithParameter("queueIsolationLevel", config.IsolationLevel)
- .WithParameter("numberOfRetries", config.NumberOfRetries)
- .WithParameter("path", busConfig.QueuePath)
- .WithParameter("enablePerformanceCounters", busConfig.EnablePerformanceCounters)
- .As<ITransport>()
- .SingleInstance();
- builder.RegisterType<RhinoQueuesMessageBuilder>()
- .As<IMessageBuilder<MessagePayload>>()
- .SingleInstance();
- builder.Update(container);
- }
+ //public void RegisterMsmqTransport(Type queueStrategyType)
+ //{
+ // var builder = new ContainerBuilder();
+ // builder.RegisterType(queueStrategyType)
+ // .WithParameter("endpoint", config.Endpoint)
+ // .As<IQueueStrategy>()
+ // .SingleInstance();
+ // builder.RegisterType<MsmqMessageBuilder>()
+ // .As<IMessageBuilder<Message>>()
+ // .SingleInstance();
+ // builder.RegisterType<ErrorAction>()
+ // .WithParameter("numberOfRetries", config.NumberOfRetries)
+ // .As<IMsmqTransportAction>()
+ // .SingleInstance();
+ // builder.RegisterType<MsmqSubscriptionStorage>()
+ // .WithParameter("queueBusListensTo", config.Endpoint)
+ // .As<ISubscriptionStorage>()
+ // .SingleInstance();
+ // builder.RegisterType<MsmqTransport>()
+ // .WithParameter("endpoint", config.Endpoint)
+ // .WithParameter("threadCount", config.ThreadCount)
+ // .WithParameter("queueIsolationLevel", config.IsolationLevel)
+ // .WithParameter("transactional", config.Transactional)
+ // .WithParameter("consumeInTransaction", config.ConsumeInTransaction)
+ // .As<ITransport>()
+ // .SingleInstance();
+ // builder.RegisterAssemblyTypes(typeof(IMsmqTransportAction).Assembly)
+ // .Where(x => typeof(IMsmqTransportAction).IsAssignableFrom(x) && x != typeof(ErrorAction))
+ // .As<IMsmqTransportAction>()
+ // .SingleInstance();
+ // builder.Update(container);
+ //}
- public void RegisterRhinoQueuesOneWay()
- {
- var builder = new ContainerBuilder();
- var oneWayConfig = (OnewayRhinoServiceBusConfiguration)config;
- var busConfig = config.ConfigurationSection.Bus;
- builder.RegisterType<RhinoQueuesMessageBuilder>()
- .As<IMessageBuilder<MessagePayload>>()
- .SingleInstance();
- builder.RegisterType<RhinoQueuesOneWayBus>()
- .WithParameter("messageOwners", oneWayConfig.MessageOwners)
- .WithParameter("path", busConfig.QueuePath)
- .WithParameter("enablePerformanceCounters", busConfig.EnablePerformanceCounters)
- .As<IOnewayBus>()
- .SingleInstance();
- builder.Update(container);
- }
+ //public void RegisterQueueCreation()
+ //{
+ // var builder = new ContainerBuilder();
+ // builder.RegisterType<QueueCreationModule>()
+ // .As<IServiceBusAware>()
+ // .SingleInstance();
+ // builder.Update(container);
+ //}
+
+ //public void RegisterMsmqOneWay()
+ //{
+ // var builder = new ContainerBuilder();
+ // var oneWayConfig = (OnewayRhinoServiceBusConfiguration)config;
+ // builder.RegisterType<MsmqMessageBuilder>()
+ // .As<IMessageBuilder<Message>>()
+ // .SingleInstance();
+ // builder.RegisterType<MsmqOnewayBus>()
+ // .WithParameter("messageOwners", oneWayConfig.MessageOwners)
+ // .As<IOnewayBus>()
+ // .SingleInstance();
+ // builder.Update(container);
+ //}
+
+ //public void RegisterRhinoQueuesTransport()
+ //{
+ // var busConfig = config.ConfigurationSection.Bus;
+ // var builder = new ContainerBuilder();
+ // builder.RegisterType<PhtSubscriptionStorage>()
+ // .WithParameter("subscriptionPath", busConfig.SubscriptionPath)
+ // .As<ISubscriptionStorage>()
+ // .SingleInstance();
+ // builder.RegisterType<RhinoQueuesTransport>()
+ // .WithParameter("threadCount", config.ThreadCount)
+ // .WithParameter("endpoint", config.Endpoint)
+ // .WithParameter("queueIsolationLevel", config.IsolationLevel)
+ // .WithParameter("numberOfRetries", config.NumberOfRetries)
+ // .WithParameter("path", busConfig.QueuePath)
+ // .WithParameter("enablePerformanceCounters", busConfig.EnablePerformanceCounters)
+ // .As<ITransport>()
+ // .SingleInstance();
+ // builder.RegisterType<RhinoQueuesMessageBuilder>()
+ // .As<IMessageBuilder<MessagePayload>>()
+ // .SingleInstance();
+ // builder.Update(container);
+ //}
+
+ //public void RegisterRhinoQueuesOneWay()
+ //{
+ // var builder = new ContainerBuilder();
+ // var oneWayConfig = (OnewayRhinoServiceBusConfiguration)config;
+ // var busConfig = config.ConfigurationSection.Bus;
+ // builder.RegisterType<RhinoQueuesMessageBuilder>()
+ // .As<IMessageBuilder<MessagePayload>>()
+ // .SingleInstance();
+ // builder.RegisterType<RhinoQueuesOneWayBus>()
+ // .WithParameter("messageOwners", oneWayConfig.MessageOwners)
+ // .WithParameter("path", busConfig.QueuePath)
+ // .WithParameter("enablePerformanceCounters", busConfig.EnablePerformanceCounters)
+ // .As<IOnewayBus>()
+ // .SingleInstance();
+ // builder.Update(container);
+ //}
public void RegisterSecurity(byte[] key)
{
@@ -284,5 +318,5 @@ public void RegisterNoSecurity()
.As<IElementSerializationBehavior>().SingleInstance();
builder.Update(container);
}
- }
+ }
}
@@ -1,54 +1,54 @@
-using System;
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using Autofac;
using Autofac.Core;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
using System.Linq;
-namespace Rhino.ServiceBus
-{
- public class AutofacServiceLocator : IServiceLocator
- {
- private readonly IContainer container;
-
- public AutofacServiceLocator(IContainer container)
- {
- this.container = container;
- }
-
- public T Resolve<T>()
- {
- return container.Resolve<T>();
- }
-
- public object Resolve(Type type)
- {
- return container.Resolve(type);
- }
-
- public bool CanResolve(Type type)
- {
- return container.IsRegistered(type);
- }
-
- public IEnumerable<T> ResolveAll<T>()
- {
- return container.Resolve<IEnumerable<T>>();
+namespace Rhino.ServiceBus
+{
+ public class AutofacServiceLocator : IServiceLocator
+ {
+ private readonly IContainer container;
+
+ public AutofacServiceLocator(IContainer container)
+ {
+ this.container = container;
+ }
+
+ public T Resolve<T>()
+ {
+ return container.Resolve<T>();
}
- public IEnumerable<IHandler> GetAllHandlersFor(Type type)
- {
- var services = container.ComponentRegistry.Registrations
- .SelectMany(r => r.Services.OfType<TypedService>())
- .Where(pService => type.IsAssignableFrom(pService.ServiceType));
+ public object Resolve(Type type)
+ {
+ return container.Resolve(type);
+ }
- return services.Select(service => (IHandler)new DefaultHandler(type, service.ServiceType, () => container.ResolveService(service)));
- }
+ public bool CanResolve(Type type)
+ {
+ return container.IsRegistered(type);
+ }
- public void Release(object item)
- {
- //Not needed for autofac
- }
- }
+ public IEnumerable<T> ResolveAll<T>()
+ {
+ return container.Resolve<IEnumerable<T>>();
+ }
+
+ public IEnumerable<IHandler> GetAllHandlersFor(Type type)
+ {
+ var services = container.ComponentRegistry.Registrations
+ .SelectMany(r => r.Services.OfType<TypedService>())
+ .Where(pService => type.IsAssignableFrom(pService.ServiceType));
+
+ return services.Select(service => (IHandler)new DefaultHandler(type, service.ServiceType, () => container.ResolveService(service)));
+ }
+
+ public void Release(object item)
+ {
+ //Not needed for autofac
+ }
+ }
}
Oops, something went wrong.

0 comments on commit 360a88f

Please sign in to comment.