The ASP.NET 1.x session state model is based on the mode attribute, which is a closed enumerated type—the SessionStateMode enum. To support a new mode (for example, the Oracle table), you need to extend the enum type and modify the code of the session state module. These changes must be repeated each time you need a new extension.
ASP.NET provider model is an evolution of the ASP.NET 1.x session state managers inspired by the Adapter design pattern.
A provider is a software module that provides a uniform interface between a service and a data source. Providers abstract physical storage media, in much the same way that device drivers abstract physical hardware devices.
Two key aspects differentiate the ASP.NET 1.x session state model from the ASP.NET 2.0 provider model:
- First is that ASP.NET 2.0 model is based on a richer and more flexible extensibility mechanism.
- Secondly, it makes use of base classes instead of interfaces.
ASP.NET 2.0's Adapter design pattern offers a better and more flexible code design. An Adapter class implements an interface known to its clients and provides access to an instance of a class not known to its clients. An Adapter object provides an interface's functionality without having to assume which class is being used to implement that interface. The only variation to the Adapter pattern is that a base class is used instead of an interface.
In ASP.NET 2.0, you use the provider model to achieve several tasks, the most important of which are:
- The implementation of a read/write mechanism to persist the user profile
- The creation of a user-defined repository of user credentials that supports most common operations, such as verifying the existence of a user, adding and deleting users, and so forth
- The creation of a user-defined repository for user roles
- The definition of the site map
- The introduction of newer types of data storage for the session state
Provider Model Implementation
The implementation of the provider model consists of two distinct elements: the configuration layer and the storage layer. The configuration layer provides information for identifying and instantiating the physical provider object that manages the stored data. The storage layer is the physical entity that stores and manages the data. Depending on the feature, it can be Active Directory, an Oracle or SQL Server table, or an XML file.
The configuration layer provides a strongly typed model to get and set property values for the user profile object. The user profile object is represented with a collection of typed properties expressed in the web.config. The HTTP runtime parses the information above and creates a class. The class is compiled on the fly and added to the application's AppDomain. An instance of the class is also exposed through the Profile property on the HttpContext class. The user profile object is filled with stored data when the request starts, and any modified values are restored upon exit. Reading and writing are operations the user profile providers perform.
ASP.NET 2.0 comes with two user profile providers. Each uses a different data engine. The default provider uses an Access database; the other provider is for SQL Server. You also can write custom providers. The provider writes data into the database of choice and is responsible for the final schema of the data. A user profile provider must be able to either serialize the type (by using XML serialization and binary object serialization, for example) or know how to extract significant information from it.
Provider Model in ASP.NET 2.0:
At its core, the ASP.NET 2.0 provider infrastructure allows customers to extend some of the out-of-the-box system functionality and change the underlying implementation while keeping the top-level interface intact. Providers are relatively simple components with as few methods and properties as possible.
Other providers (for example, the membership provider) perform different tasks, such as creating a new user, deleting existing users, or validating a given user. However, no matter the operations performed, the provider supplies a common and immutable programming interface for tasks that helper classes perform—tasks that the client doesn't know in advance and that can work with any sort of storage medium.
THe provider model in ASP.NET 2.0 has two key benefits:
- It makes the whole infrastructure much more resilient and flexible.
- It enables developers to port ASP.NET 2.0 into portions of their existing infrastructures that were developed for version 1.x easily. In this sense, it promotes reusability and smoothes migration.
All providers have certain characteristics in common. All, for example, initialize themselves when the ASP.NET run-time calls the Initialize method that they inherit from ProviderBase, and all must be thread-safe.
Providers are loaded when the application using them first accesses a feature of the corresponding service, and they're instanced just once per application (that is, per application domain).
No comments:
Post a Comment