Static Field in IHttpModule

  • Thread starter Thread starter Osama Sayed
  • Start date Start date
O

Osama Sayed

I have a class that implements IHttpModule to handle URLs with a "RESTful"
nature. It handles them according to a custom configuration section in the
website's Web.Config file. My questions are:
1. Does each client call result in a new instance of my IHttpModule class
being created?
2. Is it better to re-read my custom configuration each time or to add a
static member field containing my class that inherits from
ConfigurationSection so that configuration is always available to the
IHttpModule? Would this be faster at all?
3. If I DO end up creating a static member field (it IS better) will this
affect scalability or cause the site to be somehow stateful instead of
stateless?

Thank you,
Sammy
 
Hi,

Osama said:
I have a class that implements IHttpModule to handle URLs with a "RESTful"
nature. It handles them according to a custom configuration section in the
website's Web.Config file. My questions are:
1. Does each client call result in a new instance of my IHttpModule class
being created?

According to this page and others I read, it doesn't.
http://www.devx.com/vb2themax/Article/19901/0/page/2

The instance will be created on the first call to dynamic content in the
application (ASPX, ASMX...) and will then "filter" every request going
to this web application.
2. Is it better to re-read my custom configuration each time or to add a
static member field containing my class that inherits from
ConfigurationSection so that configuration is always available to the
IHttpModule? Would this be faster at all?

Obviously, avoiding to re-read the configuration file is faster. The
question is: How much faster, and what problems does it cause if you
cache it.

For example, can the configuration change during run time? If yes, how
do you manage the differences between the cache and the file? Who's in
charge of deleting the cache, and when? Etc... These are all design
questions that may influence the implementation.
3. If I DO end up creating a static member field (it IS better) will this
affect scalability or cause the site to be somehow stateful instead of
stateless?

If you cache something, your application will be stateful. However, I
believe that while web sites may be stateless, web applications are
mostly stateful. If it's managed correctly, it shouldn't be a problem.
Thank you,
Sammy

HTH,
Laurent
 
Back
Top