Stas_P

Masstransit: handle commands faults

Jun 26th, 2012
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. ServiceBusFactory.New(sbc => {
  2. //...
  3. /// FaultHandlerExtensions is used to simplify reflection stuff
  4. MethodInfo extensionMethod = typeof (FaultHandlerExtensions)
  5.                             .GetMethod("FaultHandler"
  6.                             BindingFlags.Public | BindingFlags.Static);
  7. sbc.Subscribe(subs =>
  8.                     {
  9.                         subs.LoadFrom(context.Resolve<ILifetimeScope>());
  10.                         var iBus = context.Resolve<IInfrastructureBus>();
  11.  
  12. //let's dynamically create handlers for the whole commands that are in the appropriate assembly :)
  13. foreach (Type messageType in typeof (IMessage).Assembly.GetTypes().Where(t => !t.IsAbstract && !t.IsInterface && t.IsAssignableTo<Command>()))
  14. {
  15. extensionMethod.MakeGenericMethod(messageType).Invoke(null, new object[] {subs, iBus});
  16. });
  17.  
  18. });
  19.  
  20.  
  21. ///.......
  22.  
  23.  
  24. public static class FaultHandlerExtensions
  25.     {
  26.         public static HandlerSubscriptionConfigurator<Fault<T>> FaultHandler<T>(this SubscriptionBusServiceConfigurator configurator, IInfrastructureBus iBus) where T : class
  27.         {
  28.             EnsureThat.IsNotNull(configurator);
  29.             EnsureThat.IsNotNull(iBus);
  30.             //...
  31.             return configurator.Handler<Fault<T>>(t => iBus.Publish(new SendEmail
  32.                                                                         {
  33.                                                                         //..
  34.                                                                         }));
  35.         }
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment