Thanks guys,
Both responses indicated that ProcessRequest is immediately called upon
retrieval from the pool. This is in fact where we have implemented
transaction initialization code which runs when a transaction start.
All of our transaction processors derive from a base transaction processor
class. The base implements IHttpHandler, and so all of the derived classes
do as well. The base implements the IsReusable method and sets the return
value to true so all derived classes are now pooled. Developers of the
derived classes don't need to do anything to make this happen since this
behavior is all inherited from the base class.
Derived classes naturally implement ProcessRequest; obviously - this is how
each transaction implements its own particular processing. So transaction
developers can implement whatever pre-transaction processing is necessary at
the commencement of this method. What I was looking for is a way to
implement application-wide transaction pre-processing in the base class in a
manner which precludes reliance on the transaction developers to properly
implement such.
Is there any way to do this? Or do I need to simply rely on the developers
of the derived transaction classes to take care of this?
Thanks for your advice!
Joseph Geretz
"Anthony Jones" <> wrote in message
news:%...
> "Joseph Geretz" <> wrote in message
> news:...
>> Is there any sort of lifecycle event which my object (implements
>> IHttpHandler) receives when it is released to the pool, or retrieved from
>> the pool?
>>
>> Naturally, I need to keep these objects as stateless as possible, however
>> some intra-transaction state accumulation is necessary. It would be
>> helpful
>> to have an event which is fired when the instance is retrieved from the
>> pool
>> so that pre-transaction initialization can be performed to ensure that
>> the
>> object is in its pristine state ready to being the next transaction. In
>> my case,
>> these objects derive from a base class and so I could implement such
>> pre-initialization in the base class.
>>
>
> I'm not sure I understand this. Are you saying that you maintain some
> state in the handler between requests? This state is may be related to an
> in progress transaction? How would you guarantee that subsequent requests
> would pick up the correct instance of the handler involved in the
> transaction?
>
> You can determine that the handler is retrieved from the pool then its
> ProcessRequest method is called. At that point its either a fresh
> instance or an instance retrieved from the pool, you could use a prvate
> boolean feild to track that.
>
> There is no specific event that tracks pool removal, you would need to use
> a finalizer (implement the IDisposable interface). That wouldn't tell you
> when the item was dropped from the pool immediately only when its finally
> GCed, however since both operations are arbitary it wouldn't make much
> difference.
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
|