public static MessagingBusBuilder WithLoopbackQueue <T>(this MessagingBusBuilder builder, string name)
     where T : Message
 {
     return(builder
            .Publications((options) => options.WithQueue <T>(name))
            .Subscriptions((options) => options.ForQueue <T>(name)));
 }
Beispiel #2
0
    /// <summary>
    /// Adds JustSaying services to the registry.
    /// </summary>
    /// <param name="registry">The <see cref="ConfigurationExpression"/> to add JustSaying services to.</param>
    /// <param name="configure">A delegate to a method to use to configure JustSaying.</param>
    /// <exception cref="ArgumentNullException">
    /// <paramref name="registry"/> or <paramref name="configure"/> is <see langword="null"/>.
    /// </exception>
    public static void AddJustSaying(this ConfigurationExpression registry, Action <MessagingBusBuilder, IContext> configure)
    {
        if (registry == null)
        {
            throw new ArgumentNullException(nameof(registry));
        }

        if (configure == null)
        {
            throw new ArgumentNullException(nameof(configure));
        }

        registry.AddRegistry <JustSayingRegistry>();

        registry
        .For <MessagingBusBuilder>()
        .Singleton()
        .Use(
            nameof(MessagingBusBuilder),
            (context) =>
        {
            var builder = new MessagingBusBuilder()
                          .WithServiceResolver(new ContextResolver(context));

            configure(builder, context);

            var contributors = context.GetAllInstances <IMessageBusConfigurationContributor>();

            foreach (var contributor in contributors)
            {
                contributor.Configure(builder);
            }

            return(builder);
        });

        registry
        .For <IMessagePublisher>()
        .Singleton()
        .Use(
            nameof(IMessagePublisher),
            (context) =>
        {
            var builder = context.GetInstance <MessagingBusBuilder>();
            return(builder.BuildPublisher());
        });

        registry
        .For <IMessagingBus>()
        .Singleton()
        .Use(
            nameof(IMessagingBus),
            (context) =>
        {
            var builder = context.GetInstance <MessagingBusBuilder>();
            return(builder.BuildSubscribers());
        });
    }
Beispiel #3
0
 public static MessagingBusBuilder WithLoopbackQueue <T>(this MessagingBusBuilder builder, string name,
                                                         Action <QueueSubscriptionBuilder <T> > configure = null)
     where T : Message
 {
     return(builder
            .Publications((options) => options.WithQueue <T>(o => o.WithName(name)))
            .Subscriptions((options) => options.ForQueue <T>(subscriptionBuilder =>
     {
         subscriptionBuilder.WithName(name);
         configure?.Invoke(subscriptionBuilder);
     })));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MessagingConfigurationBuilder"/> class.
 /// </summary>
 /// <param name="busBuilder">The <see cref="MessagingBusBuilder"/> that owns this instance.</param>
 internal MessagingConfigurationBuilder(MessagingBusBuilder busBuilder)
 {
     BusBuilder = busBuilder;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionsBuilder"/> class.
 /// </summary>
 /// <param name="parent">The <see cref="MessagingBusBuilder"/> that owns this instance.</param>
 internal SubscriptionsBuilder(MessagingBusBuilder parent)
 {
     Parent = parent;
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServicesBuilder"/> class.
 /// </summary>
 /// <param name="busBuilder">The <see cref="MessagingBusBuilder"/> that owns this instance.</param>
 internal ServicesBuilder(MessagingBusBuilder busBuilder)
 {
     BusBuilder = busBuilder;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AwsClientFactoryBuilder"/> class.
 /// </summary>
 /// <param name="busBuilder">The <see cref="MessagingBusBuilder"/> that owns this instance.</param>
 internal AwsClientFactoryBuilder(MessagingBusBuilder busBuilder)
 {
     BusBuilder = busBuilder;
 }
Beispiel #8
0
 public void Configure(MessagingBusBuilder builder)
 {
     builder.Messaging((p) => p.WithRegion("eu-west-1"));
 }
Beispiel #9
0
 public void Configure(MessagingBusBuilder builder)
 {
     builder.Publications((p) => p.WithQueue <QueueMessage>(options => options.WithName(QueueName)))
     .Subscriptions((p) => p.ForQueue <QueueMessage>(cfg => cfg.WithName(QueueName)));
 }
Beispiel #10
0
 public void Configure(MessagingBusBuilder builder)
 {
     builder.Services(
         (p) => p.WithMessageMonitoring(ServiceProvider.GetRequiredService <MyMonitor>));
 }
Beispiel #11
0
 public void Configure(MessagingBusBuilder builder)
 {
     builder.Client(
         (options) => options.WithSessionCredentials("accessKeyId", "secretKeyId", "token")
         .WithServiceUri(TestEnvironment.SimulatorUrl));
 }
 public void Configure(MessagingBusBuilder builder)
 {
     builder.Publications((p) => p.WithQueue <QueueMessage>())
     .Subscriptions((p) => p.ForQueue <QueueMessage>());
 }
 public void Configure(MessagingBusBuilder builder)
 => _configure(builder);
        /// <summary>
        /// Adds JustSaying services to the service collection.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/> to add JustSaying services to.</param>
        /// <param name="configure">A delegate to a method to use to configure JustSaying.</param>
        /// <returns>
        /// The <see cref="IServiceCollection"/> specified by <paramref name="services"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="services"/> or <paramref name="configure"/> is <see langword="null"/>.
        /// </exception>
        public static IServiceCollection AddJustSaying(this IServiceCollection services, Action <MessagingBusBuilder, IServiceProvider> configure)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            // Register as self so the same singleton instance implements two different interfaces
            services.TryAddSingleton((p) => new ServiceProviderResolver(p));
            services.TryAddSingleton <IHandlerResolver>((p) => p.GetRequiredService <ServiceProviderResolver>());
            services.TryAddSingleton <IServiceResolver>((p) => p.GetRequiredService <ServiceProviderResolver>());

            services.TryAddSingleton <IAwsClientFactory, DefaultAwsClientFactory>();
            services.TryAddSingleton <IAwsClientFactoryProxy>((p) => new AwsClientFactoryProxy(p.GetRequiredService <IAwsClientFactory>));
            services.TryAddSingleton <IMessagingConfig, MessagingConfig>();
            services.TryAddSingleton <IMessageMonitor, NullOpMessageMonitor>();

            services.AddSingleton <MessageContextAccessor>();
            services.TryAddSingleton <IMessageContextAccessor>(serviceProvider => serviceProvider.GetRequiredService <MessageContextAccessor>());
            services.TryAddSingleton <IMessageContextReader>(serviceProvider => serviceProvider.GetRequiredService <MessageContextAccessor>());

            services.TryAddSingleton <IMessageSerializationFactory, NewtonsoftSerializationFactory>();
            services.TryAddSingleton <IMessageSubjectProvider, GenericMessageSubjectProvider>();
            services.TryAddSingleton <IVerifyAmazonQueues, AmazonQueueCreator>();
            services.TryAddSingleton <IMessageSerializationRegister>(
                (p) =>
            {
                var config = p.GetRequiredService <IMessagingConfig>();
                return(new MessageSerializationRegister(config.MessageSubjectProvider));
            });

            services.TryAddSingleton(
                (serviceProvider) =>
            {
                var builder = new MessagingBusBuilder()
                              .WithServiceResolver(new ServiceProviderResolver(serviceProvider));

                configure(builder, serviceProvider);

                var contributors = serviceProvider.GetServices <IMessageBusConfigurationContributor>();

                foreach (var contributor in contributors)
                {
                    contributor.Configure(builder);
                }

                return(builder);
            });

            services.TryAddSingleton(
                (serviceProvider) =>
            {
                var builder = serviceProvider.GetRequiredService <MessagingBusBuilder>();
                return(builder.BuildPublisher());
            });

            services.TryAddSingleton(
                (serviceProvider) =>
            {
                var builder = serviceProvider.GetRequiredService <MessagingBusBuilder>();
                return(builder.BuildSubscribers());
            });

            return(services);
        }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PublicationsBuilder"/> class.
 /// </summary>
 /// <param name="parent">The <see cref="MessagingBusBuilder"/> that owns this instance.</param>
 internal PublicationsBuilder(MessagingBusBuilder parent)
 {
     Parent = parent;
 }