private static void PreloadProducers(IOutboundRouter router, IServiceProvider serviceProvider) { var brokers = serviceProvider.GetRequiredService <IBrokerCollection>(); var logger = serviceProvider.GetRequiredService <ISilverbackLogger <IEndpointsConfigurationBuilder> >(); router.Endpoints.ForEach(endpoint => PreloadProducer(brokers, endpoint, logger)); }
/// <summary> /// Adds and outbound endpoint for the specified message type. /// </summary> /// <typeparam name="TMessage"> /// The type of the messages to be published to this endpoint. /// </typeparam> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="router"> /// The <see cref="IOutboundRouter{TMessage}" /> to be used to determine the destination endpoint. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound <TMessage>( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, IOutboundRouter <TMessage> router) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(router, nameof(router)); return(endpointsConfigurationBuilder.AddOutbound(typeof(TMessage), router)); }
/// <summary> /// Adds a singleton outbound router with an instance specified in /// <paramref name="implementationInstance" /> to the /// <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />. /// </summary> /// <param name="silverbackBuilder"> /// The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add /// the services to. /// </param> /// <param name="implementationInstance"> /// The instance of the service. /// </param> /// <returns> /// The <see cref="ISilverbackBuilder" /> so that additional calls can be chained. /// </returns> public static ISilverbackBuilder AddSingletonOutboundRouter( this ISilverbackBuilder silverbackBuilder, IOutboundRouter implementationInstance) { Check.NotNull(silverbackBuilder, nameof(silverbackBuilder)); silverbackBuilder.Services.AddSingleton(implementationInstance); return(silverbackBuilder); }
/// <summary> /// Adds and outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="messageType"> /// The type of the messages to be published to this endpoint. /// </param> /// <param name="router"> /// The <see cref="IOutboundRouter{TMessage}" /> to be used to determine the destination endpoint. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Type messageType, IOutboundRouter router) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(router, nameof(router)); endpointsConfigurationBuilder.GetOutboundRoutingConfiguration() .Add(messageType, _ => router); return(endpointsConfigurationBuilder); }
/// <summary> /// Adds an outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="messageType"> /// The type of the messages to be published to this endpoint. /// </param> /// <param name="router"> /// The <see cref="IOutboundRouter{TMessage}" /> to be used to determine the destination endpoint. /// </param> /// <param name="preloadProducers"> /// Specifies whether the producers must be immediately instantiated and connected. When <c>false</c> the /// <see cref="IProducer" /> will be created only when the first message is about to be produced. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Type messageType, IOutboundRouter router, bool preloadProducers = true) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(messageType, nameof(messageType)); Check.NotNull(router, nameof(router)); endpointsConfigurationBuilder.GetOutboundRoutingConfiguration() .Add(messageType, _ => router); if (preloadProducers) { PreloadProducers(router, endpointsConfigurationBuilder.ServiceProvider); } return(endpointsConfigurationBuilder); }