public void ChainBuilt(IChain chain) { var subscriptionNotification = new ChainBuilderNotifier(); var services = new ChainBuilderSetupServices(subscriptionNotification); var chainFunc = this.newchainBuilder.BuildFunc(services); this.newChain = new Chain <TNewMessageType>(chainFunc, chain.Dispose); subscriptionNotification.Notify(this.newChain); }
/// <summary> /// Builds the message handler chain /// </summary> /// <typeparam name="TMessageType">The message type /// </typeparam> /// <param name="chainBuilder"> /// The message Handler chain Builder. /// </param> /// <returns> /// The <see cref="Func<TmessageType,CancellationToken,Task>"/>. /// </returns> public static Func <TMessageType, CancellationToken, Task> BuildFunc <TMessageType>(this IChainBuilder <TMessageType> chainBuilder) { var subscriptionNotification = new ChainBuilderNotifier(); var services = new ChainBuilderSetupServices(subscriptionNotification); var func = chainBuilder.BuildFunc(services); var chain = new Chain <TMessageType>(func, ActionHelpers.NoAction); subscriptionNotification.Notify(chain); return(func); }
/// <summary> /// Initializes a new instance of the <see cref="ParallelMessageHandlerChainPublisher{TMessageType}"/> class. /// </summary> /// <param name="ChainBuilder"> /// The message handler chain builder /// </param> public ParallelMessageHandlerChainPublisher(ChainBuilder <MessageAndHandler <TMessageType> > ChainBuilder) { ChainBuilder.Handler(this.PublishAsync); var subscriptionNotification = new ChainBuilderNotifier(); var services = new ChainBuilderSetupServices(subscriptionNotification); this.publisher = ChainBuilder.BuildFunc(services); var chain = new Chain <MessageAndHandler <TMessageType> >(this.publisher); subscriptionNotification.Notify(chain); }
/// <summary> /// Builds a message handler chain from the decorators and the handler added /// </summary> /// <param name="disposeAction"> /// The action to call when the chain dispose method is called. /// </param> /// <returns> /// The <see cref="Func<TmessageType,CancellationToken,Task>"/>. /// </returns> public IChain <TMessageType> BuildChain(Action disposeAction = null) { var subscriptionNotification = new ChainBuilderNotifier(); var services = new ChainBuilderSetupServices(subscriptionNotification); var func = this.BuildFunc(services); disposeAction = disposeAction ?? ActionHelpers.NoAction; var chain = new Chain <TMessageType>(func, disposeAction); subscriptionNotification.Notify(chain); return(chain); }
public void ChainBuilt(IChain chain) { this.parentChain = chain; foreach (var branch in this.branches) { var builder = new ChainBuilder <TMessageType>(); branch(builder); var notifier = new ChainBuilderNotifier(); var services = new ChainBuilderSetupServices(notifier); var chainFunc = builder.BuildFunc(services); this.handlers.Add(chainFunc); var newChain = new Chain <TMessageType>(chainFunc, () => this.Unsubscribe(chainFunc)); notifier.Notify(newChain); } }
private static BusOptions <TMessageType> UseSubscriptionChain <TMessageType>( BusOptions <TMessageType> options, ChainBuilder <MessageAndHandler <TMessageType> > builder) { if (builder.HasHandler == false) { builder.Handler(PublishToSubscription.PublishAsync); } var subscriptionNotification = new ChainBuilderNotifier(); var services = new ChainBuilderSetupServices(subscriptionNotification); var chainFunc = builder.BuildFunc(services); var newChain = new Chain <MessageAndHandler <TMessageType> >(chainFunc); subscriptionNotification.Notify(newChain); options.UseCustomPublisher(new ParallelMessageHandlerChainPublisher <TMessageType>(chainFunc)); return(options); }
/// <summary> /// Create a message handler chain to set up a subscription /// </summary> /// <typeparam name="TMessageType">The message type</typeparam> /// <param name="subscriptions">The subscriptions interface</param> /// <param name="setupAction">The method called to configure the message handler chain for the new subscription</param> /// <returns>The new message handler chain</returns> public static IChain <TMessageType> Subscribe <TMessageType>( this IMessageBusSubscriptions <TMessageType> subscriptions, Action <IChainBuilder <TMessageType> > setupAction) { var builder = new ChainBuilder <TMessageType>(); setupAction(builder); var subscriptionNotification = new ChainBuilderNotifier(); var services = new ChainBuilderSetupServices(subscriptionNotification); var chainFunc = builder.BuildFunc(services); var subscription = subscriptions.Subscribe(chainFunc); var chain = new Chain <TMessageType>(chainFunc, subscription.Dispose); subscriptionNotification.Notify(chain); return(chain); }
/// <summary> /// Creates a new message handler func /// </summary> /// <param name="config"> /// The config. /// </param> /// <typeparam name="T"> /// The message type /// </typeparam> /// <returns> /// A message handler chain builder /// </returns> public static Func <T, CancellationToken, Task> Func <T>(Action <IChainBuilder <T> > config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } var builder = Builder <T>(); config(builder); var notifier = new ChainBuilderNotifier(); var func = builder.BuildFunc(new ChainBuilderSetupServices(notifier)); #pragma warning disable CC0022 // Should dispose object notifier.Notify(new Chain <T>(func)); #pragma warning restore CC0022 // Should dispose object return(func); }