/// <inheritdoc/>
        public async Task <object> ReceiveAsync(IWebHookExecutionContext context)
        {
            EventPayload meta = JsonConvert.DeserializeObject <EventPayload>(context.Payload.ToString());

            var handlerType = Options.Handlers[meta.EventType];

            using (var scope = ServiceScopeFactory.CreateScope())
            {
                var receiver = (IAzureDevOpsHandler)scope.ServiceProvider.GetRequiredService(handlerType);

                return(await receiver.HandleAsync(context));
            }
        }
        public async Task <object> HandleAsync(IWebHookExecutionContext context)
        {
            var payload = (TPayload)Parse(context.Payload);

            await EventBus.PublishAsync(typeof(HookEvent), new HookEvent
            {
                Id           = context.Identifier,
                EventType    = EventType,
                ReceiverName = AzureDevOpsConstants.ReceiverName,
                Payload      = payload
            });

            return(null);
        }
        /// <inheritdoc/>
        public ReceiverResolution Select(IWebHookExecutionContext context)
        {
            if (!Handlers.Handlers.ContainsKey(context.HandlerName))
            {
                throw new NotImplementedException(context.HandlerName);
            }

            var matchingReceiver = Receivers.Receive.Find(x =>
                                                          string.Equals(x.HandlerName, context.HandlerName, StringComparison.OrdinalIgnoreCase) &&
                                                          string.Equals(x.Identifier, context.Identifier, StringComparison.OrdinalIgnoreCase));

            if (matchingReceiver == null)
            {
                return(null);
            }

            return(new ReceiverResolution(
                       Handlers.Handlers[context.HandlerName],
                       matchingReceiver
                       ));
        }