ASP.NET 2.0 Provider Model

By yogeshsingh

Introduction

Change in software industry is very frequent. The solutions we create today are challenged by each new technology, but building a solution from scratch to incorporate these new developments is not always feasible.
So the ASP.NET team wanted to create a solution that is not only simple and elegant but also extendable. More specifically, they wanted a scalable, easy-to-use, well-documented system with full control over its internal implementations. The result is a design termed the provider model that allows you to extend or change the behavior of an application or control based on business requirements.
At the first glimpse, the provider model seems to be an enhanced version of the abstract factory pattern. But on reality it is more than that, It is a system in itself that incorporates a number of patterns like the singleton, the strategy, and the component configurator pattern.

Reason for Provider model
1. Fixed Choices    
There is usually a limitation to a fixed number of options in published APIs.
2. Fixed Internal Behaviors
Suppose ,we  want to change some internal behaviors of ASP.NET APIs, for example changing how ASP.NET Session sets or retrieves values from its out-of-process store. Today the design is constrained i.e either all data can be fetched or none of it can be retrieved.
3. Fixed Data Schema       
Fixed schemas are typically built to be really good for everyone, but excellent for no one.
These are common problems that all technologies share: the inability to change core behavior or functionality of published APIs. The solution to this is  The Provider Model of ASP.NET 2.0 “
Earlier, web.config file was responsible for defining roles in our application. With ASP.NET 2.0 around, there is support for Membership and Role provider classes, like, the SqlMembershipProvider and SqlRoleProvider. However, the only constraint is that these are designed to work with SQL Server only, but there is a facility to extend these classes to create your own custom provider implementations with support for any data store.
The ASP.NET Provider Model provides a pluggable architecture for working with providers. It gives the flexibility of using the custom providers; where-in one can even implement their own providers in their applications.
Well, what is a provider, anyway? The applications need some way of storing states, either in the temporary main memory or in a persistent manner in the database. “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.”
The Membership and the Role Management Providers follow the provider pattern through the usage of an interface for a contract based approach. The base class for all the providers in such a pattern is the ProviderBase abstract class. All the other providers are actually inherited from this ProviderBase abstract class. The MembershipProvider and the RoleProvider classes that inherit the ProviderBase class are also abstract classes.

The ProviderBase class
The following is the list of the methods and properties of the ProviderBase class in the ASP.NET 2.0 Provider Model.
·         Name
·         Description
·         Initialize ()
·         ProviderBase () this is the constructor for the ProviderBase class.The ProviderBase class is present in the System.Configuration.Provider namespace.

Benefits of the ASP.NET 2.0 Provider Model
The Provider Model offers benefits in more ways than one. These are as follows.
·         It can be used with the default implementation and customized too.
·         Provides a distinct isolation of code and the back-end implementation.
·         Facilitates isolation of tasks within the project team members.

The following are the built-in providers of the ASP.NET Provider Model.
·         Membership Providers
·         Role Management Providers
·         Profile Providers
·         Site Map Providers
·         Session State Providers
·         Web Event Providers
·         Web Parts Personalization Providers
·         Protected Configuration Providers

Conclusion
This article is mainly to introduce the Provider Model in ASP.NET 2.0 and the related concepts. It has also discussed what providers are, the types of providers and custom providers.

4 Responses to “ASP.NET 2.0 Provider Model”

  1. naveenpathak Says:

    Nice :)

    In .Net 1.1, Enterprise Library was the base to implement provide model easily and it too was completely based on Provider pattern. For example the DataAccess block has given the facility to chose your database (SQL, Oracle or any) at run time with a minor change in configuration.
    Not only this, the entire .Net plateform is developed by Microsoft by keeping in mind this very useful model and thats why you can see the interfaces like IConnection, which facilitates you to choose your database latter…not during developement. No no need to tightly integrate the DB Server with your application any more.

  2. gauravsharma82 Says:

    Hey Naveen can you please elaborate on Enterprise Library?

    Good introduction about Provider Model. I thinking in terms of layers we can divide ASP.net provider model into 3 layers, Provider Class, Configuration Layer and Storage Layer. A small debatable thing if you noticed in provider’s implementation in ASP.net is that it uses Abstract Base classes not interfaces. JAVA pluggable model uses interfaces and usually patterns are defined using interfaces only. Using abstract base classes fixes some of the issues that are associated with interfaces, like versioning issues.
    .NET platform was developed by MS only when they realized that if they did not do anything they will be out of software programming industry. Java would have killed MS. I am glad they did something even if their sole intention was to create a platform whith features copied from JAVA. Not only features, their core language is JAVA with a new funky name C#. Let’s see what all they can re implement with funky names in near future. As days goes by they keep on adding new features, which 90% of time are just wrapper classes around pre existing technologies. Just look at LINQ. LINQ is just a wrapper around delegates and anonymous methods. Anonymous methods are also a kind of wrapper. Wrapper around wrappers around already slow library function calls…huh

    Any thoughts around improving performance?

  3. naveenpathak Says:

    Yes Gaurav. I will take the opportunity to write about Enterprise Library in one of the next post. Currently I am planning to focus on Dependency Injection as I have promised about it in my latest post. But Enterprise Library will be the next one :)

  4. gauravsharma82 Says:

    Cool

Leave a Reply