I'm new to fluent and am integrating it into a .NET core solution. I'm trying to have a static mapper that returns the appropriate validator based on the passed type but I'm running into problems. See below for simplistic example:
public static class Mapper
{
public static IValidator GetValidator<T>(T instance)
{
if (instance is CustomType)
{
return new CustomTypeValidator();
}
return new DefaultValidator();
}
public static IValidator<T> GetVlidator<T>(T instance)
{
if (instance is CustomType)
{
return new CustomTypeValidator();
}
return new DefaultValidator();
}
}
The first method is unusable as IValidator only provides a Validate method that takes in an IValidationContext.
The second method can't convert the concrete validator onto the inferface.
I've looked into DI options and can register the concrete validator for each type, but then I would still need to map based on type and can't cast the concrete validator as IValidator< T>.
Should I just perform the validation on a separate service where I can explicitly perform the methods based on type and just return the result?