示例#1
0
        /// <summary>
        /// Adds and configures the consistence services for the consistency.
        /// </summary>
        /// <param name="services">The services available in the application.</param>
        /// <param name="setupAction">An action to configure the <see cref="TransportOptions" />.</param>
        /// <returns>An <see cref="TransportBuilder" /> for application services.</returns>
        public static TransportBuilder AddTransport(this IServiceCollection services, Action <TransportOptions> setupAction)
        {
            if (setupAction == null)
            {
                throw new ArgumentNullException(nameof(setupAction));
            }

            ServiceCollection = services;

            services.AddTransient <ITransportPublisher, TransportPublisher>();

            //Options and extension service
            var options = new TransportOptions();

            setupAction(options);

            foreach (var serviceExtension in options.Extensions)
            {
                serviceExtension.AddServices(services);
            }

            services.Configure(setupAction);

            return(new TransportBuilder(services));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TransportPublisher"/> class.
 /// </summary>
 /// <param name="transport">The transport.</param>
 /// <exception cref="ArgumentNullException">transport</exception>
 public TransportPublisher(
     ITransport transport,
     IOptions <TransportOptions> transportOptions)
 {
     _transport = transport ?? throw new ArgumentNullException(nameof(transport));
     _options   = transportOptions.Value;
 }