Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ServiceBusFactory.New(sbc => {
- //...
- /// FaultHandlerExtensions is used to simplify reflection stuff
- MethodInfo extensionMethod = typeof (FaultHandlerExtensions)
- .GetMethod("FaultHandler",
- BindingFlags.Public | BindingFlags.Static);
- sbc.Subscribe(subs =>
- {
- subs.LoadFrom(context.Resolve<ILifetimeScope>());
- var iBus = context.Resolve<IInfrastructureBus>();
- //let's dynamically create handlers for the whole commands that are in the appropriate assembly :)
- foreach (Type messageType in typeof (IMessage).Assembly.GetTypes().Where(t => !t.IsAbstract && !t.IsInterface && t.IsAssignableTo<Command>()))
- {
- extensionMethod.MakeGenericMethod(messageType).Invoke(null, new object[] {subs, iBus});
- });
- });
- ///.......
- public static class FaultHandlerExtensions
- {
- public static HandlerSubscriptionConfigurator<Fault<T>> FaultHandler<T>(this SubscriptionBusServiceConfigurator configurator, IInfrastructureBus iBus) where T : class
- {
- EnsureThat.IsNotNull(configurator);
- EnsureThat.IsNotNull(iBus);
- //...
- return configurator.Handler<Fault<T>>(t => iBus.Publish(new SendEmail
- {
- //..
- }));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment