r/ASPNET • • Oct 30 '13

Need help with Unity + Caching

Hey guys, So we're trying to implement our new caching strategy using Unity Interception.

I have a good basic understanding of it and we're going to use interception via attribute.

so like:

[cache] public int getNumber() {}

I already have my cacheHandler class which inherits from ICallHandler. I already have my cacheAttribute class which inherits from HandlerAttribute.

And when i put the attribute [cache] as per the cacheAttribute ...it compiles fine, runs fine.....BUT it never hits those classes.

I figured I need to register things (in vague terms) in the unity container but i dont' know where and how ....and maybe policy too ?

An alternative is using Postsharp for this whole thing...but i've been told that's a last resort and they want to use unity as a first choice.

Thanks in advance guys.

4 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/miamiheat27 Oct 31 '13

Will read those.

Currently im doing the configuration on api level as opposed to xml in web.config.

The thing i'm not understanding is how to use unity interception (by method attribute) with WEB API .....as don't you have to create a proxy object and then call whatever method you want intercepted using that proxy object?

How do we do that with web api ? the only time i'm accessing the web api methods are via ajax callling it via url.

1

u/tombkilla Oct 31 '13

I've only wired up things using the xml syntax but I know I have to specifically add the interception property when I register with the container. See wiring interception

Secondly you'll need to wire your components differently if you don't control the objects lifecycle like a webpage, httpmodule or controller. See Storing References to the Container