Ejemplo n.º 1
0
        private async Task <bool> ProcessEvent <T>(T value) where T : IntegrationEvent
        {
            var processed = false;

            if (_subscriptionManager.HasEvent <T>())
            {
                using (var scope = _serviceScopeFactory.CreateScope())
                {
                    var subscriptions = _subscriptionManager.GetHandlersForEvent <T>();
                    foreach (var subscription in subscriptions)
                    {
                        var handler = scope.ServiceProvider.GetRequiredService(subscription);
                        if (handler == null)
                        {
                            continue;
                        }
                        var concreteType = typeof(IIntegrationEventHandler <>).MakeGenericType(typeof(T));
                        await(Task) concreteType.GetMethod("Handle").Invoke(handler, new object[] { value });
                    }
                }
                processed = true;
            }
            return(processed);
        }