예제 #1
0
        /// <summary>
        /// This method should be called before any of the other methods.  It effectivly initializes the Validation Engine.
        /// Use this overloaded method to provide your own custom validator and manager.
        /// </summary>
        /// <param name="validator">A <see cref="IValidator"/> representing a custom validator.</param>
        /// <param name="manager">A <see cref="IValidationManager"/> representing a custom manager.</param>
        /// <exception cref="System.InvalidOperationException">If the Engine has already been initialized, this will be thrown.</exception>
        /// <exception cref="System.ArgumentNullException">If validator or manager are null.</exception>
        public static void Initialize(IValidator validator, IValidationManager manager)
        {
            if (_isInitialized)
                throw new InvalidOperationException("Initialization of the Validation Engine can only happen once.");

            if (validator == null)
                throw new ArgumentNullException("validator");
            if (manager == null)
                throw new ArgumentNullException("manager");

            CurrentValidator = validator;
            CurrentManager = manager;

            CurrentValidator.RegisterService(typeof(IValidationManager), CurrentManager);
            CurrentValidator.RegisterService(typeof(IValidator), CurrentValidator);

            _isInitialized = true;
        }