Exemplo n.º 1
0
        private void RegisterHandlers(HandlerScanner handlerScanner)
        {
            foreach (var item in handlerScanner)
            {
                var messageType = item.Key;
                var handlerType = item.Value;

                addMessageHandler
                .MakeGenericMethod(new Type[] { messageType, handlerType })
                .Invoke(this, new object[] { });
            }
        }
Exemplo n.º 2
0
        public static void AddSimpleMessaging(this IServiceCollection services, HandlerScanner handlerScanner = null)
        {
            if (handlerScanner == null)
            {
                handlerScanner = new HandlerScanner();
                var assembly = Assembly.GetCallingAssembly();
                handlerScanner.ScanAssembly(assembly);
            }

            foreach (var item in handlerScanner)
            {
                services.AddTransient(item.Value);
            }

            services.AddSingleton <IMessaging>(serviceProvider => new SimpleMessaging(new MsDiHandlerProvider(serviceProvider), handlerScanner));
        }
Exemplo n.º 3
0
        public static void AddAzureServiceBus(this IServiceCollection services,
                                              Action <ServiceBusConfigurationBuilder> builder)
        {
            var configBuilder = new ServiceBusConfigurationBuilder();

            builder(configBuilder);
            var config = configBuilder.Build();

            var scanner = new HandlerScanner();

            scanner.ScanAndRegisterHandlers(services, configBuilder.IncludeInScan);

            var connectionBuilder = new ServiceBusConnectionStringBuilder(config.ConnectionString);
            var connection        = new ServiceBusConnection(connectionBuilder);

            services.AddSingleton(connection);
            services.AddSingleton <IServiceBus>(p => new AzureServiceBus(connection, config, p));

            if (configBuilder.StartSubscriptions == null)
            {
                return;
            }

            var bus = services.BuildServiceProvider().GetRequiredService <IServiceBus>();
            var subscriptionBuilder = new SubscriptionBuilder(bus);

            if (config.CanReceive)
            {
                subscriptionBuilder.ConsumeQueue(config.EndpointName);
            }

            configBuilder.StartSubscriptions(subscriptionBuilder);

            var container = subscriptionBuilder.Build();

            services.AddSingleton(container);
        }
Exemplo n.º 4
0
 public MessagingCore(IHandlerProvider handlerProvider, HandlerScanner handlerScanner)
 {
     this.handlerProvider = handlerProvider ?? throw new ArgumentNullException(nameof(handlerProvider));
     RegisterHandlers(handlerScanner);
 }