views:

413

answers:

1

My web application (MonoRail, Windsor, ActiveRecord) has a Startable import service and one or more Startable import readers. When, for example, a file is dropped in a directory, a reader parses the file, passes the data to the service, which updates and/or creates objects through repositories. The problem I have is that these Startable services live outside the request scope (where there's a SessionScope from Begin to End), so when the service encounters a lazy collection, there's no SessionScope around to help it do its magic. Cue LazyInitializationException :).

Any ideas how to solve this nicely? Perhaps using an interceptor to create and dispose a SessionScope around the method that processes the data? Equip the repositories with methods that perform eager fetching? I want to keep the services unaware of ActiveRecord, because my dependency paranoia says we might want to use a different persistence mechanism one day.

A: 

You already answered it:

using an interceptor to create and dispose a SessionScope around the method that processes the data

Mauricio Scheffer
Hmm, yes... It's definitely neater than having to write all that eager-fetching HQL and what not. Adds a bit of configuration, but it's manageble. Any idea how/if I can configure an interceptor to intercept a specific method without having to code it into the interceptor itself?
Bergius
You could have the interceptor take a string parameter that is the name of the method to intercept... then assign each interceptable component a different instance of the interceptor.
Mauricio Scheffer
Another option would be decorating your interceptable methods with an attribute, then checking that attribute from the interceptor.
Mauricio Scheffer
This is hardly the place to discuss this... please ask again on the forums (http://forum.castleproject.org/) or google group (http://groups.google.com/group/castle-project-users)
Mauricio Scheffer