예제 #1
0
 /// <summary>
 /// Gets the value
 /// </summary>
 /// <returns></returns>
 public string GetString(ICommonContext context)
 {
     try {
         return(_stringProvider(context));
     }
     catch (NullReferenceException ex) {
         throw new FluentValidationMessageFormatException("Could not build error message- the message makes use of properties from the containing object, but the containing object was null.", ex);
     }
 }
예제 #2
0
        public virtual string GetString(ICommonContext context)
        {
            var errorCode = ErrorCodeFunc?.Invoke(context);

            if (errorCode != null)
            {
                string result = ValidatorOptions.Global.LanguageManager.GetString(errorCode);

                if (!string.IsNullOrEmpty(result))
                {
                    return(result);
                }
            }

            return(ValidatorOptions.Global.LanguageManager.GetString(_key));
        }
예제 #3
0
        /// <summary>
        /// Gets the service provider associated with the validation context.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public static IServiceProvider GetServiceProvider(this ICommonContext context)
        {
            IValidationContext actualContext = null;

            switch (context)
            {
            case CustomContext cc:
                actualContext = cc.ParentContext;
                break;

            case MessageBuilderContext mbc:
                actualContext = mbc.ParentContext;
                break;

            case PropertyValidatorContext pvc:
                actualContext = pvc.ParentContext;
                break;

            case IValidationContext vc:
                actualContext = vc;
                break;
            }

            if (actualContext != null)
            {
                if (actualContext.RootContextData.TryGetValue("_FV_ServiceProvider", out var sp))
                {
                    if (sp is IServiceProvider serviceProvider)
                    {
                        return(serviceProvider);
                    }
                }
            }

            throw new InvalidOperationException("The service provider has not been configured to work with FluentValidation. Making use of InjectValidator or GetServiceProvider is only supported when using the automatic MVC integration.");
        }
예제 #4
0
 public UserRepository(IMapper mapper, ICommonContext erpContext)
 {
     this._mapper     = mapper;
     this._erpContext = erpContext;
 }
예제 #5
0
 /// <summary>
 /// Construct the error message template
 /// </summary>
 /// <returns>Error message template</returns>
 public string GetString(ICommonContext context)
 {
     return(_message);
 }
 public string GetString(ICommonContext context)
 {
     return(Factory.Invoke(context as TContext));
 }