Operation Handler Dependencies

Topics: Web Api
Feb 8, 2012 at 1:57 AM

Is there anyway built in to specify dependencies?

I am adding all my handlers through a convention, so they are in no specific order.

I added an attribute DependsOn(Type) to my handlers that require it, but I may just end up making an ordering instead.

But I was wondering if there is a way currently built in, to handle operation handler dependencies? And is there any plan to add it if there isn't?

Feb 8, 2012 at 6:14 AM

Check out this blog post.  I believe it's for an older preview (maybe 4/5), but might shed some light on operation handler ordering.  I remember reading something along the lines that WebApi detects dependencies and creates a permutation based upon input/output parameters.  I can't say concretely, nor provide much confidence in this answer.

http://pfelix.wordpress.com/2011/08/13/wcf-web-apioperation-handlers/  (towards the bottom of the post)

Feb 8, 2012 at 6:38 AM

If it is supposed to do that, it isn't. It errors saying that it will never receive that input. It is running them in the order they are added.

I made a handler called A that takes in a Foo, and outputs Bar, and a handler B that takes in a HttpRequestMessage and outputs a Foo.

It errored saying that "A would never receive an input of Foo". 

Also what about dependencies that do not work with input, output?

The reason it has came up, is I am trying to implement 3 different authentication methods.
So I let them all run, then at the end, I run the real authorization based on the user (roles, etc).
If there is no user, because no security method picked them up, I throw an error. But the first 3 need to run before the last.