Пример #1
0
            public Validators(Core.ValidationExpressionBuilder expressionBuilder, bool isThreadSafe)
            {
                var threadSafteyMode = isThreadSafe ? LazyThreadSafetyMode.None : LazyThreadSafetyMode.ExecutionAndPublication;

                ReturnFirstErrorValidator = new Lazy <Core.ValidationImplementationContext <Func <T, Core.ValidationError?> > >(expressionBuilder.Build <T>, threadSafteyMode);
                CollectAllErrosValidator  = new Lazy <Core.ValidationImplementationContext <Action <T, ICollection <Core.ValidationError> > > >(expressionBuilder.BuildFull <T>, threadSafteyMode);
            }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Validator"/> class.
        /// </summary>
        /// <param name="isThreadSafe">Set to <c>true</c> to indicate that the validator will be called from a thread-safe context.</param>
        /// <param name="recursionPolicy">The recursion policy.</param>
        /// <param name="validatorProvider">The validator provider.</param>
        /// <param name="converters">The converters.</param>
        public Validator(bool isThreadSafe, IRecursionPolicy recursionPolicy, IValidatorProvider validatorProvider, IEnumerable <IValidationExpressionConverter> converters)
        {
            _isThreadSafe = isThreadSafe;

            if (isThreadSafe)
            {
                _nonThreadSafeCache = new Dictionary <Type, object>();
            }
            else
            {
                _threadSafeCache = new ConcurrentDictionary <Type, object>();
            }

            _expressionBuilder = new Core.ValidationExpressionBuilder(recursionPolicy, validatorProvider, converters);
        }