public static IQueryProcessorExtensionBuilder AddDefaultPolicies(this IQueryProcessorExtensionBuilder builder)
        {
            var defaultRetryPolicy = Policy
                                     .Handle <Exception>()
                                     .WaitAndRetry(new[]
            {
                TimeSpan.FromMilliseconds(50),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(150)
            });

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreaker(1, TimeSpan.FromMilliseconds(500));

            var policyRegistry = new PolicyRegistry
            {
                { Constants.RetryPolicyName, defaultRetryPolicy },
                { Constants.CircuitBreakerPolicyName, circuitBreakerPolicy }
            };

            builder.RegisterDecorator(typeof(RetryableQueryDecorator <,>));
            builder.AddContextBagItem(Constants.ContextBagKey, policyRegistry);

            return(builder);
        }
        public static IQueryProcessorExtensionBuilder AddJsonQueryLogging(this IQueryProcessorExtensionBuilder builder, Action <JsonSerializerSettings> settings = null)
        {
            JsonSerializerSettings serializerSettings = null;

            if (settings != null)
            {
                serializerSettings = new JsonSerializerSettings();
                settings(serializerSettings);
            }

            builder.RegisterDecorator(typeof(QueryLoggingDecorator <,>));
            builder.AddContextBagItem(Constants.ContextBagKey, new NewtonsftJsonSerializer(serializerSettings));

            return(builder);
        }
        public static IQueryProcessorExtensionBuilder AddPolicies(this IQueryProcessorExtensionBuilder builder, IPolicyRegistry policyRegistry)
        {
            if (policyRegistry == null)
            {
                throw new ArgumentNullException(nameof(policyRegistry));
            }

            if (!policyRegistry.Has(Constants.RetryPolicyName))
            {
                throw new ConfigurationException($"The policy registry is missing the {Constants.RetryPolicyName} policy which is required");
            }

            if (!policyRegistry.Has(Constants.CircuitBreakerPolicyName))
            {
                throw new ConfigurationException($"The policy registry is missing the {Constants.CircuitBreakerPolicyName} policy which is required");
            }

            builder.RegisterDecorator(typeof(RetryableQueryDecorator <,>));
            builder.AddContextBagItem(Constants.ContextBagKey, policyRegistry);

            return(builder);
        }