feO2x/Light.Validation

Validation Context Factory

feO2x opened this issue · 0 comments

feO2x commented

Currently, the library is not opinionated about how Validation Contexts are created. If the the user wants to configure the validation context differently, a Func<ValidationContext> can be provided to validators as a factory.

I am wondering if it would be useful to use a centralized IValidationContextFactory which creates all contexts. Usually, this factory can be a singleton throughout the lifetime of a process and create all validation contexts in a centralized manner. I'm currently worrying if we should also take references like HttpContext so that based on the request, the ValidationContext can be created (e.g. for translating error messages to the correct language).

We should first check if IHttpContextAccessor actually has performance problems that we might want to avoid. According to Microsoft docs of AsyncLocal<T>, there are some, while David Fowler himself does not know about them: aspnet/Hosting#793 (comment)