public override void PostConfigureServices(ServiceCollectionContext context)
        {
            //TODO:此处为了解决使用端直接注入IConfigureOptions<EventBusRabbitMqOptions>对象而导致RabbitMqConnection属性不起作用
            var implementationInstances = context.Services
                                          .Where(p => p.ServiceType == typeof(IConfigureOptions <EventBusRabbitMqOptions>))
                                          .Select(p => (IConfigureOptions <EventBusRabbitMqOptions>)p.ImplementationInstance)
                                          .ToList();

            if (!implementationInstances.Any())
            {
                return;
            }

            var eventBusRabbitMqOptions = new EventBusRabbitMqOptions();

            foreach (var implementationInstance in implementationInstances)
            {
                implementationInstance.Configure(eventBusRabbitMqOptions);
            }

            context.Services.AddRabbitMq(options =>
            {
                options.Connection = eventBusRabbitMqOptions.RabbitMqConnection;
            });
        }
        public void AddServices(IServiceCollection services)
        {
            var option = new EventBusRabbitMqOptions();

            _options.Invoke(option);
            services.AddRabbitMq(option.RabbitMqOptions);

            services.AddSingleton <IMessagePublisher, RabbitMqMessagePublisher>();
            services.AddSingleton <IMessageSubscribe, RabbitMqMessageSubscribe>();
            services.Configure(_options);
        }
Exemplo n.º 3
0
 public EventBusRabbitMq(
     IRabbitMqPersistentConnection persistentConnection,
     IRabbitMqMessageConsumerFactory rabbitMqMessageConsumerFactory,
     IEventBusSubscriptionsManager subsManager,
     IEventHandlerFactory eventHandlerFactory,
     ILogger <EventBusRabbitMq> logger,
     IOptions <EventBusRabbitMqOptions> options)
 {
     _eventBusRabbitMqOptions        = options.Value;
     _persistentConnection           = persistentConnection;
     _rabbitMqMessageConsumerFactory = rabbitMqMessageConsumerFactory;
     _subsManager         = subsManager;
     _eventHandlerFactory = eventHandlerFactory;
     _logger = logger;
     RabbitMqMessageConsumerDic   = new ConcurrentDictionary <string, IRabbitMqMessageConsumer>();
     _subsManager.OnEventRemoved += SubsManager_OnEventRemoved;
 }