public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { ISellerRepository sellerRepository = (ISellerRepository)context.HttpContext.RequestServices.GetService(typeof(ISellerRepository)); CreateSellerContactDTO sellerContactDTO = (CreateSellerContactDTO)context.ActionArguments["sellerContactDTO"]; if (!await sellerRepository.ExistsAsync(sellerContactDTO.SellerId)) { context.ModelState.AddModelError("SellerId", "The given seller id does not correspond to an existing seller"); } await next(); }