private async Task Consumer_Received(object sender, BasicDeliverEventArgs @event) { string message = @event.RoutingKey; if (handlers.TryGetValue(message, out List <Type> listOfHandlers)) { using (var scope = _serviceScopeFactory.CreateScope()) { foreach (var handlerType in listOfHandlers) { var handler = scope.ServiceProvider.GetService(handlerType) as IEventHandler; var messageType = handlerType.GenericTypeArguments[0]; var messageBody = messageSerializer.Deserilize(@event.Body, messageType); await handler.Handle(messageBody); } } } }