Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 7th, 2008, 04:00 AM
Registered User
 
Join Date: Sep 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default SiteProvider

In the BLL in, say, the Category.cs file, where the code reads:

            List<CategoryDetails> recordset = SiteProvider.Articles.GetCategories();
            categories = GetCategoryListFromCategoryDetailsList(recordset);
            BaseArticle.CacheData(key, categories);

What is the purpose of the SiteProvider.Articles bit. I dont understand the instantition of an instance piece in the SiteProvider.cs file. Can I eliminate the creation of the instance and just directly execute the GetCategories() method? How would I accomplish this?

Thanks


  #2 (permalink)  
Old September 7th, 2008, 04:24 AM
Authorized User
 
Join Date: Jul 2008
Location: , , South Africa.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to TashaAT
Default

Do you have the book that goes with TBH?

  #3 (permalink)  
Old September 7th, 2008, 04:36 AM
Registered User
 
Join Date: Sep 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yea, i got the book. Im just confused about this instance instantiation bit. Also..the book mentioned something about getting the ProviderType from the 'thebeerhouse' configsection..i assume that was the web.config file..but i see nothing for providertype.

  #4 (permalink)  
Old September 7th, 2008, 11:57 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
quote:Originally posted by Reza



What is the purpose of the SiteProvider.Articles bit. I dont understand the instantition of an instance piece in the SiteProvider.cs file. Can I eliminate the creation of the instance and just directly execute the GetCategories() method? How would I accomplish this?

Thanks
Remember that the architecture has been designed to allow for multiple providers for any given module. You can indicate the provider you want to use in the custom configuration section of web.config using the providerType property. For the articles module, the default is MB.TheBeerHouse.DAL.SqlClient.SqlArticlesProvider. But you could, for example, add an Oracle-based provider and do something like this:

<articles pageSize="10" providerType="MB.TheBeerHouse.DAL.OracleClient.Ora cleArticlesProvider" />

So, we need the SiteProvider class to tell us which provider is in use. It does that by creating an instance of the providerType that is specified in the config file, or the default type if no providerType is specified.

Make sense?



  #5 (permalink)  
Old September 7th, 2008, 12:37 PM
Registered User
 
Join Date: Sep 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Lee,
your reply kinda cleared the air. So if I heard correctly, the Default providerType is "MB.THeBeerhouse.DAL.SQLClient.SqlArticlesProvider " ...when I downloaded the code, this was not in the Web.Config. Is it this section? I dont see any providerTypes for forums, polls etc!

   <theBeerHouse defaultConnectionStringName="LocalSqlServer">
      <contactForm mailTo="thebeerhouse@wrox.com"/>
      <articles pageSize="10" />
      <polls archiveIsPublic="true" votingLockByIP="false" />
      <newsletters fromEmail="thebeerhouse@wrox.com" fromDisplayName="TheBeerHouse" />
      <forums threadsPageSize="8" hotThreadPosts="10" bronzePosterPosts="10" silverPosterPosts="20" goldPosterPosts="50" />
      <store sandboxMode="true" businessEmail="thebeerhouse@wrox.com" />
   </theBeerHouse>


So if im strictly using, say SQL, how could I rewrite the ArticlesProvider to create an instance of ArticlesProvider type? I tried this in the Articles Provider class and it didnt work.


               _instance = (ArticlesProvider)Activator.CreateInstance(
                  Type.GetType(MB.TheBeerHouse.DAL.SQLClient.SqlArti clesProvider));

I get the squiggly line and the error: The best overloaded match for 'System.Activator.CreateInstance' has some invalid arguments.

Thanks

  #6 (permalink)  
Old September 7th, 2008, 12:53 PM
Registered User
 
Join Date: Sep 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok..so i found the default provider in the ConfigSection.cs file...but i still cant figure out how to code the providertype explicitly, can someone show me how to do this please.

So if im strictly using, say SQL, how could I rewrite the ArticlesProvider to create an instance of ArticlesProvider type? I tried this in the Articles Provider class and it didnt work.


               _instance = (ArticlesProvider)Activator.CreateInstance(
                  Type.GetType(MB.TheBeerHouse.DAL.SQLClient.SqlArti clesProvider));

I get the squiggly line and the error: The best overloaded match for 'System.Activator.CreateInstance' has some invalid arguments.

  #7 (permalink)  
Old September 7th, 2008, 01:08 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Do this instead:

_instance = (ArticlesProvider)Activator.CreateInstance(
   Type.GetType("MB.TheBeerHouse.DAL.SQLClient.SqlArt iclesProvider"));

Type.GetType() needs the name of the type as a string.

But if your true goal is to not allow alternate providers, you might want to consider gutting the provider model out the solution altogether...

  #8 (permalink)  
Old September 7th, 2008, 01:20 PM
Registered User
 
Join Date: Sep 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Lee,
yes..im a trying to take out the provider model completely..just having trouble figuring out how. Can you tell me if the following is correct please?

To take out provider model to use SQL explicitly:
For the DAL, I would have one DAL class..lets call it SqlArticles. This just has all the calls to the stored procedures as would be defined in SqlArticlesProvider.cs.

Do I still need the instance creation bit? or can I eliminate that completely..if so how?

  #9 (permalink)  
Old September 7th, 2008, 02:10 PM
Registered User
 
Join Date: Sep 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am storing a list of schools (id, name and pnemonic) in a db and am trying to figure out how to use the DAL and BLL n-tier model given in the book. Can someone take a look at the files in the link below and let me know if im missing something please.

Its very simple and currently only executes one stored procedure to get all the schools, I want to build on this if my method is correct.

http://rapidshare.com/files/143426845/App_Code.zip.html

Thanks.

  #10 (permalink)  
Old September 7th, 2008, 04:04 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Yes, you would just have a class that calls the stored procedures, but does not inherit or implement ArticlesProvider. You would get rid of ArticlesProvider altogether, as well as the Articles property of SiteProvider. Then, in places in your code where you call the DAL methods, you would do so directly instead of using the SiteProvider functionality.

For example:

SiteProvider.Articles.GetCategories()

would become:

SqlArticles.GetCategories()

You would also want to get rid of the providerType property for the ArticlesElement in ConfigSection, as it would now have no use.

All this being said, I am not sure why you'd want to bother messing with this at all. Leaving the provider model intact isn't hurting anything, even if you don't intend to use it.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Aricles/SiteProvider question HELP PLS crazy BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 9 March 7th, 2008 01:10 PM
SiteProvider Question zmijasu2k3 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 August 2nd, 2006 10:03 PM



All times are GMT -4. The time now is 12:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.