locked
Static Members in HttpModule RRS feed

  • Question

  • User-1776838653 posted

    I have a class that implements IHttpModule which I use to capture URLs of a "RESTful" style and handle them. I also have a class that inherits from ConfigurationSection which handles a custom Web.Config section for regular expression matching of these URLs. My questions are:

    1. Does each client call result in a new instance of my HttpModule class?
    2. Is it better to put a static member variable representing my custom configuration section handler? The reason I'm asking is: isn't it a waste to re-create an instance of the configuration section handler class every time the application gets hit (by a client call)?
    3. If I do end up creating a static member variable in my HttpModule class, would this be considered stateful? I need to make sure the application scales (is stateless) across a server farm.

    Thank you,
    Sammy

     

    Monday, September 18, 2006 6:35 AM

Answers

  • User390817712 posted

    1) No - there will not be one instance per request, but the runtime will create multiple instances of your module. The instances can be reused across many requests.

    2) It won't be creating an instance on every hit, so it's not as much overheard as you think.

    3) It is stateful, but you are not holding user state (like a user's shopping cart), so it's not the kind of state we typically have to worry about.

    This article might help: http://www.odetocode.com/Articles/89.aspx

    Keep in mind your module will be created for each HttpApplication instance.

     

    HTH,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 18, 2006 10:51 PM