Is there a way to use domain objects as API GET route parameters?
My reason is, I have an API action like this:
public async Task<IActionResult> CancelOnlineMeeting(string id)
I'd like to the api to parse the incoming string into an id object like this:
public class Id
{
public string Value { get; }
public Id(string value)
{
//example logic
if(string.IsNullOrEmpty(value))
{
throw new ArgumentNullException("value");
}
if(value.Length > 10)
{
throw new ValidationException("Invalid length");
}
Value = value.Trim();
}
}
And then use the route:
public async Task<IActionResult> CancelOnlineMeeting(Id id)
The benefit would be to validate the Id object value in one place, when using the Id object in multiple actions.