in .net Framework <= 4.7.2, in validation context, you could get the current HttpRequest by accessing the HttpContext.
For example, I had a piece of code which looked like this:
public sealed class AccessValidator : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext context)
{
// validate stuff, if all true -> yield ok.
// if is not valid
var request = HttpContext.Current.Request;
// store/log the request payload.
}
}
This cannot be done when using .net Core 2.1.
I saw a post regarding injection of IHttpContextAccessor or something, but it exposes the request in almost every place.
Since this is an external library to my server, I wish it not rely on server code injections because then it creates a dependence I don't want to be.
Is there any known way to handle this or around this?