I have been trying to create an ISessionFactory that has a list of filters as a property (so it can be specified in the XML configuration) and enables each of the filters whenever OpenSession() is called.
Unfortunately, I have been stymied at every turn. I've subclassed LocalSessionFactoryObject and SimpleDelegatingSessionFactory, mixed-and-matched every way I can think of, but there's always some syntax or run-time error that keeps it from working.
Can anyone give me an example of how to do this?
Thanks in advance.
[Update]
I've been asked to provide some code to illustrate my issue. I don't think that's really relevant to the question I'm asking, but I can elaborate:
I figured that to make sure the filters are enables whenever a new session is opened I'd have to have my own OpenSession method. It seemed the best way to do this was to subclass DelegatingSessionFactory, add the filter-list property and a method like this
public new ISession OpenSession()
{
var rtn = base.OpenSession();
foreach (var filter in filters)
rtn.EnableFilter(filter);
return rtn;
}
When I had Spring construct this as my ISessionFactory object, though, I got runtime errors about not having an exception translator. So, I figured I'm better off also subclassing LocalSessionFactoryObject and having it create an ISessionFactory of my new type with the filter list, rather than the default type. To do this I tried to override NewSessionFactory, but then I got a runtime error about not having a DbProvider defined, and when I tried to copy the code that handles this from LocalSessionFactoryObject I got a bunch of syntax errors because of the scope of some members...
In short, something that seemed like it should be simple -- and that in fact I rather expected many to have done before me -- turned in a coding safari. That's why I'm looking for someone who's already done it, or who at least understands the framework better than I do.