Resolving dependency in Attribute

Topics: Customizing Orchard
Mar 19, 2014 at 1:22 PM
I have my own authorize attribute and I'd like to use IAuthorizer to authorize a permission inside of my attribute. How can I get at the WorkContext so I can call TryResolve to get an instance of it?

Or I guess, how could I inject IAuthorize into the Attribute?
Mar 20, 2014 at 8:12 PM
This is a demonstration for WebAPI attributes, but you can do the same for MVC attributes:
Mar 20, 2014 at 8:33 PM
Thanks. Yea, I looked at that, and ultimately was able to use that example to get it to work.

My original problem was that I knew that example existed, but couldn't get my ApiController to work, because of some reference issues in my module. Basically, my module wanted to use System.Web.Http v5.0 and Orchard was using 4.0 blah blah blah. Ended up just referencing the older version. It worked.

I just couldn't figure out how to get the WorkContext from a MVC attribute.

...also, i noticed in Fiddler, I'm periodically getting a 302 followed by an access denied page. I didn't think ApiControllers fell under the normal front-end permissions stuff? I put AlwaysAccessible on it and it seems to work.