public INeedARequestContext Policies(IPolicyRegistry policyRegistry)
        {
            if (policyRegistry == null)
            {
                throw new ArgumentNullException(nameof(policyRegistry));
            }

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

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

            _policyRegistry = policyRegistry;
            return(this);
        }
Example #2
0
        public static IBuildTheQueryProcessor Policies(this IBuildTheQueryProcessor lastStageBuilder, IPolicyRegistry policyRegistry)
        {
            var builder = lastStageBuilder.ToQueryProcessorBuilder();

            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");
            }

            return(builder.ContextBagItem(Constants.ContextBagKey, policyRegistry));
        }
        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);
        }