In MVC this sort of thing is pretty trivial. Let's say I have an MVC action signature:
public ActionResult SomeAction(InjectedObject a, ConstructedObject b)
And let's say that the request from the client contains the ConstructedObject and I want to build the InjectedObject in the framework pipeline automatically. (In this example, InjectedObject is on lots of actions, maybe even all of them.) I could just create an InjectedObjectModelBinder : IModelBinder and register an instance of that binder when the application starts.
That binder would simply construct an instance of InjectedObject however I need to. (From request data, from some other source, a combination of sources, etc.) This worked really well for cross-cutting concerns.
However, is there a way to do this in WebAPI? There's a new IModelBinder, but it seems like its use assumes only a single model on the input. And my Googling so far has also pointed to that assumption. Is it even possible in WebAPI to inject something into the pipeline like this as a cross-cutting concern while still having the constructed model from the post body?
The specific use case here is that I'd like to build a custom authorization-related object, in this case from request headers. I could build it in the action, but every action would need to. I could add an extension method onto the controller, but that would hurt unit testing. The preferred method would be to simply inject it into the pipeline so that I can inject a mock when unit testing the controller actions.
Does WebAPI support this? Or perhaps is there another preferred approach?
