Define Interceptor to intercept just one action of my controller

0 views
Skip to first unread message

jsmorris

unread,
Sep 3, 2008, 8:47:04 PM9/3/08
to Castle Project Users
Is there a way to define an Interceptor to just intercept one action
on my controller?

I have a need to start a background process to do some database
updates and would only like it to fire when a user hits the Index
action on my controller (instead of every method on the controller).
I thought I saw a blog post or something on the net about doing this,
but I cannot seem to find it again.

Interceptors can only be defined at the class level and I poked around
the IInvocation that was passed to the Intercept method, but didn't
see an easy way to see which action(method) was called.

I realize I can just put the code inside of the controller's method,
but seemed out of place and an Interceptor might be the better
solution to this scenario.

Ayende Rahien

unread,
Sep 4, 2008, 12:45:24 AM9/4/08
to castle-pro...@googlegroups.com
Just make a check in the interceptor and don't do anything for anything else, that is the simplest approach, which has almost zero cost.
In general, I would STRONGLY recommend against doing something like that in an interceptor, this is part of what the method is doing.

josh robb

unread,
Sep 4, 2008, 3:42:25 AM9/4/08
to castle-pro...@googlegroups.com
+1 - magic is bad...

however - you might want to look at Filters if your intent on not
putting this in the action.

j.

jsmorris

unread,
Sep 4, 2008, 1:28:31 PM9/4/08
to Castle Project Users
Thanks for the advise guys. I now see that an Interceptor/Filter
might not be the best approach for what I attend to do. I will put my
logic inside the controller's method.

Gauthier Segay

unread,
Sep 4, 2008, 7:23:03 PM9/4/08
to Castle Project Users
I agree, if controller / httpcontext sensitive, it would better fit a
filter.

About the magic interception mechanism, does that is bad:

http://svn.castleproject.org:8080/svn/castle/trunk/Facilities/AutomaticTransactionManagement/Castle.Facilities.AutomaticTransactionManagement/TransactionInterceptor.cs
Reply all
Reply to author
Forward
0 new messages