c# - how do I get Controller data from ModelValidatorContext in ASP.NET Core -
i have custom model validator:
public class myvalidationattribute : attribute, imodelvalidator { public ienumerable<modelvalidationresult> validate(modelvalidationcontext context) { ... } }
let's say, purposes of validation need data controller. not expert in reflection voodoo, can some data controller:
var descriptor = context.actioncontext.actiondescriptor controlleractiondescriptor;
or
var typeinfo = descriptor.controllertypeinfo;
but if have variable in controller, say, repository of dbcontext passed via di (although doubt if important) - how can access variable validator?
note: simplified use case mcve purposes. realize brittle way go , there better way validation when need do remote validation. use case different.
Comments
Post a Comment