コード例 #1
0
        private async Task ProcessEvent(string eventName, string message)
        {
            if (!_subscriptionManager.HasSubscriptionsForEvent(eventName))
            {
                throw new InvalidOperationException($"No Subscriptions for event {eventName}");
            }

            using (var scope = _serviceProvider.CreateScope())
            {
                var eventType        = _subscriptionManager.GetEventTypeByName(eventName);
                var concreteType     = typeof(IIntegrationEventHandler <>).MakeGenericType(eventType);
                var eventHandlerType = _subscriptionManager.GetEventHandlerType(eventName);
                var handler          = scope.ServiceProvider.GetService(eventHandlerType);
                var integrationEvent = JsonConvert.DeserializeObject(message, eventType);
                await(Task) concreteType
                .GetMethod(nameof(IIntegrationEventHandler <IIntegrationEvent> .Handle))
                .Invoke(handler, new[] { integrationEvent });
            }
        }