I am implementing a custom parameter binder that inherits HttpParameterBinding and will apply custom behavior to certain parameters. In some cases I do not want to apply the custom behavior in which case I want to follow whatever Web API does by default. This decision would be made in ExecuteBindingAsync. How do I implement this default behavior in ExecuteBindingAsync?
I believe this is typically done by simply not applying the parameter binding when registering the binding during startup (in other words the handler to the ParameterBindingRules collection would return null, allowing Web API to bind the default binding to the parameter). However in my case I need to decide whether to apply the binding at runtime, so I need to do this in ExecuteBindingAsync.
I am looking to do something like the following in my custom HttpParameterBinding class:
public override async Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)
{
if (IsCustomBindingNeeded()) {
// apply custom binding logic... call SetValue()... I'm good with this part
}
else {
// ***************************************************************
// This is where I want to use the default implementation.
// Maybe something like this (using a made up class name):
await return new WhateverDefaultParameterBinding().ExecuteBindingAsync(metadataProvider, actionContext, cancellationToken);
// ...or at least be able to call GetValue() and get the correct value and then I can call SetValue()
// ***************************************************************
}
}
I've tried calling GetValue() but it always returns null. I assume there is some additional step that needs to be performed so that the base class (HttpParameterBinding) can create the value.
My preference is to directly call whatever method within the .NET framework contains that default logic. I would prefer not to have to duplicate that logic.