Hi guys, i have a problem about FluentValidation. I am taking this error when i am starting app:
System.InvalidCastException: 'Unable to cast object of type 'DevFramework.Northwind.Entities.Concrete.Product' to type 'FluentValidation.IValidationContext'.'
Broken Fluent Validation Code:
using FluentValidation;
namespace DevFramework.Core.CrossCuttingConcerns.Validation.FluentValidation
{
public class ValidatorTool
{
public static void FluentValidate(IValidator validator, object entity)
{
var result = validator.Validate((IValidationContext)entity);
if (result.Errors.Count > 0)
{
throw new ValidationException(result.Errors);
}
}
}
}
-----------------------------------------------------------------------
FluentValidationAspect(I am using postsharp) which i used for:
[FluentValidationAspect(typeof(ProductValidator))]
[CacheRemoveAspect(typeof(MemoryCacheManager))]
[LogAspect(typeof(FileLogger))]
public Product Add(Product product)
{
return _productDal.Add(product);
}
Thanks!
What I have tried:
I've tried this code:
public class ValidatorTool
{
public static void FluentValidate(IValidator validator, object entity)
{
var result = validator.Validate(entity);
if (result.Errors.Count > 0)
{
throw new ValidationException(result.Errors);
}
}
}
and I took this error:
cannot convert from 'object' to 'FluentValidation.IValidationContext' DevFramework.Core 17 Active