using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.DependencyInjection; using System; namespace Infrastructure.Extensions { public static class ControllerExtensions { public static ModelMetadata GetModelMetadata(this ControllerBase controller) { if (controller is null) { throw new ArgumentNullException(nameof(controller)); } return controller.HttpContext.RequestServices.GetRequiredService().GetMetadataForType(typeof(T)); } } }