The ASP.NET 2.0 Provider Model
by Dino Esposito of WintellectMost applications need to save and retrieve data to and from persistent media. In ASP.NET, a good example of this kind of persistent data is the session state. Developers write applications that use the session state, but neither end-users nor developers really know where or how the session state is held. ASP.NET developers can control the location of the data to some extent, however, by instructing the ASP.NET runtime to save and retrieve the state from local memory, memory of an external process, or even a SQL Server table.
In spite of the various storage options, the programming interface to the session state remains the same (the web.config file). For example, to move the session state from the local memory (the ASP.NET cache) to a SQL Server table, all you do is modify an attribute in the web.config file. You don't need to recompile or even touch the code. This article reveals the magic behind this behavior, which the ASP.NET 2.0 provider model provides.
ASP.NET 1.x Session State Module
The session state module figures out the name of a state manager class based on the session mode attribute in the web.config file. Next, it uses a switch statement to instantiate the right component, as in the following pseudo-code:
int mode = sessionStateConfig.Mode;
switch (mode)
{
case 1:
this.stateManager = new InProcStateClientManager();
break;
case 2:
this.stateManager = new OutOfProcStateClientManager();
break;
case 3:
this.stateManager = new SqlStateClientManager();
break;
}
All three state client manager classes implement the same interface, thus providing the same functionality to the HTTP module.
Although this model is effective and fully functional, it hardly is extensible. What if you want to store your session state in, say, an Oracle database?
Page 1 of 3
