Peter Mounce
Peter Mounce

Reputation: 4225

How do I define the order in which ServiceStack request/response filters run in when they are defined by IPlugins?

I am using ServiceStack's IPlugin mechanism in combination with request and response filters defined by attributes on my Service implementations. The attribute based filters can have an int to define their priority.

When defining a global request/response filter, there doesn't seem to be a way to set up the order in which that executes compared to other global request/response filters.

For example, I'd like my execution timing plugin's filters to be the first request filter, and the last response filter, to capture the execution time of requests fully.

Is it possible to define priority of filter when adding on request/response filters via IPlugin.Register?

Upvotes: 1

Views: 332

Answers (1)

Peter Mounce
Peter Mounce

Reputation: 4225

I think, actually (I'm hoping Demis will comment), that there is: IPlugin wants us to implement void Register(IAppHost apphost). AppHost allows us to do

appHost.RequestFilters.Add(OnBeginRequest);
appHost.ResponseFilters.Add(OnEndRequest);

where OnBeginRequest and OnEndRequest are methods that match the delegate required.

If I then add IHasRequestFilter and IHasResponseFilter to my IPlugin implementation, and change the method names to match (or call out to them; whichever), and then implement Priority to return the int of my choice and IHasRequestFilter Copy() and IHasResponseFilter Copy() then I think I'm done; prioritised global filters registered from the plugin.

Upvotes: 1

Related Questions