Working with Custom Providers
page 4 of 8
by Brian Mains
Feedback
Average Rating: 
Views (Total / Last 10 Days): 20181/ 177

Part 3: Provider Configuration

We see in the previous initialize method that it uses settings it retrieves from the configuration file.  This is the next part of the provider setup.  To do this, the NewsletterSection exposes a DefaultProvider and Provider collection property to store the name of the default provider, and contains a list of providers that the static class will use (discussed later).  The following NewsletterSection class, inheriting from ConfigurationSection, has these properties:

Listing 6

[
ConfigurationProperty("defaultProvider",
 DefaultValue = "AspNetDatabaseNewsletterProvider"),
StringValidator(MinLength = 1)
]
public override string DefaultProvider
{
      get { return (string)this["defaultProvider"]; }
      set { this["defaultProvider"= value; }
}
[ConfigurationProperty("providers")]
public ProviderSettingsCollection Providers
{
      get { return (ProviderSettingsCollection)this["providers"]; }
}

The ProviderSettingsCollection class is a standard .NET framework collection for exposing provider elements in the configuration file.  As with any provider, you need the name of the provider to reference it by, and the type of the provider to implement, which could be located in the App_Code, bin, or global assembly cache.

Listing 7

<newsletters defaultProvider="AspNetDatabaseNewsletterProvider">
      <providers>
            <add name="AspNetDatabaseNewsletterProvider"
 type="Nucleo.Web.Providers.DatabaseNewsletterProvider, Nucleo.Web"
 connectionStringName="NucleoDB" applicationName="Business" />
      </providers>
</newsletters>

Obviously, each provider needs its own custom settings; these settings are regulated by the Initialize method we saw previously.  In that initialize method, it made sure that the connection string name and application name attributes are present.  In this way, these two portions tie in together in this way.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 7 and 7 and type the answer here:

User Comments

Title: still confused reply   
Name: Brian
Date: 8/28/2008 8:50:50 AM
Comment:
The static class is a class separate from the rest of the code, which exposes the provider base class to the public. It's responsible for instantiating it.

SO this is something that should be in the same project as the provider, but is a separate class.
Title: still confused :(   
Name: .
Date: 8/28/2008 3:19:45 AM
Comment:
Would have been nice to be able to download code. I'm at a loss as to where to put the static class - whether I put it in the application which is trying to use the providers, or in the provider code itself as a separate class.
Title: good articles   
Name: I LIKE LT
Date: 9/5/2007 9:16:47 PM
Comment:
very good articles
Title: Good   
Name: Bilal Wani
Date: 3/20/2007 7:17:27 AM
Comment:
Nice Article!!!
Title: Patil   
Name: Sandip
Date: 3/15/2007 5:16:26 PM
Comment:
Nice Article!!!

-Sandip Patil
Title: pat   
Name: sandy
Date: 3/15/2007 5:15:06 PM
Comment:
nice
Title: Good   
Name: Ramamuni Reddy
Date: 2/18/2007 11:25:54 PM
Comment:
Hello Brian Mains,
Very Good Article.

With Regrads
Ramamuni reddy Mulapaku
Title: Provider Utility   
Name: Bilal Hadiar [MVP]
Date: 2/6/2007 6:07:46 AM
Comment:
Hello Brian,
It is a well written article, congratulations!

I would like to refer you and all the readers to a utility I created a while ago that helps you generate the skeleton of a provider files in a single button click,
Check it here:
http://bhaidar.net/cs/archive/2006/07/07/376.aspx

Regards
Title: Mr.   
Name: KotiReddy.
Date: 2/6/2007 12:30:15 AM
Comment:
Very Good Article.


Regards,
Koti Reddy. S

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 1/6/2009 9:04:43 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search