Clear Dispatcher

35 views
Skip to first unread message

shapper

unread,
Sep 5, 2012, 9:03:19 AM9/5/12
to agath...@googlegroups.com
Hello,

I am using Agatha with a MVC4 application and using the configuration "ServiceLayerAndClientConfiguration".

I am injecting the IRequestDispatcher as transient in the controllers and other classes using StructureMap.

I keep Clearing the dispatcher before it can be used again ... So I have Clears in many places.


Should I inject a Fun<IRequestDispatcher> or a custom DispactherFactory? Or a RequestDispatcher wrapper that always clear?

Why not including this in the configuration:

  new ServiceLayerAndClientConfiguration { AutoClear = true; ...

Or maybe something like:

  dispatcher.GetAndClear<MyResponse>(response);

Maybe both ... It might be useful ... Is this something that could be included?

What is your advice? What have you been doing?

Thank you,
Miguel

Davy Brion

unread,
Sep 5, 2012, 10:01:50 AM9/5/12
to agath...@googlegroups.com
I've never used the in-process model, only the remote model... When you're using Agatha with a remote service, you should try to take advantage of sending batches of requests.  When you send a batch of requests, you're going to have to retrieve the responses someway.  That's why you need to call the Clear method before you can send new requests (otherwise the new responses would overwrite the old ones).

The in-process model was added later, simply because somebody asked and it was very easy to do.  But the default RequestDispatcher (which requires the usage of Clear for subsequent service calls) has been written with remote usage in mind.  In your case, you could provide your own implemention of IRequestDispatcher which automatically calls Clear when you get the response.

For instance, if you only use the  Get<TResponse>(Request request) method, you could provide an IRequestDispatcher implementation with the following implementation of that method:

public virtual TResponse Get<TResponse>(Request request) where TResponse : Response
{
Add(request);
var response = Get<TResponse>();
Clear();
return response;
}

that would of course break the behavior of every other Get method, but you could provide different implementations for them too if you want
Reply all
Reply to author
Forward
0 new messages