Getting request parameters in controllers constructor or something like that

Viewed 140

I want to add a required field to all of my methods in a controller but i have no idea how should i achieve that.I dont want to add field to all of my methods cause i feel its not the right way to do it.Here is an example :

public IActionResult GetLastLegals()
{
        return Ok(_service.GetLastInformationEnumerable((int)InformationTypeId.Legals));
}

public IActionResult GetNews([FromQuery] FilterLastInformationDto filterLastInformation)
{
    if(!ModelState.IsValid)
    {
        return BadRequest(ModelState);
    }
    return Ok(_service.GetLastInformationWithFilter(filterLastInformation, (int) InformationTypeId.News));
}


I want to add an int field to these methods and i dont want to pass it as methods input argument cause then i should change all of my methods signature.I know i can do it like

[HttpGet("Legals")]
public IActionResult GetLastLegals([FromQuery] RequiredField)
{
    return Ok(_service.GetLastInformationEnumerable((int)InformationTypeId.Legals));
}

but i feel like there is a better way to that like getting it in controller's constructor or adding it to route???? I would appreciate your ideas

0 Answers
Related