Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Getting StartedGetting Starteddataprovider class seems to reference itselfdataprovider class seems to reference itself
Previous
 
Next
New Post
1/21/2012 12:50 AM
 

Hi all,

Been reading up on DNN Modual programming, and although I understand the role of the DataProvider Class, the source code has me a bit confused.  It appears to me that the code contained in the class actually references and instantiates the very same class itself.  Is that true?  Is that even possible?

As you can see in the vb template-generated code below, The class is defined as "Public MustInherit Class DataProvider", yet there is code inside the class that references the very same class that is defined (i.e. "Private Shared objProvider As DataProvider = Nothing" and "Public Shared Shadows Function Instance() As DataProvider", and also in the "CType" function.

Could someone please explain how this is even possible? 

Thanks in advance :) 

DataProvider.vb

Public MustInherit Class DataProvider

 

#Region “Shared/Static Methods”

‘ singleton reference to the instantiated object
Private Shared objProvider As DataProvider = Nothing

‘ constructor
Shared Sub New()
CreateProvider()
End Sub

‘ dynamically create provider
Private Shared Sub CreateProvider()
objProvider = CType(Framework.Reflection.CreateObject(“data“,
“DotNetNuke.Modules.Html“, “DotNetNuke.Modules.Html“), DataProvider)
End Sub

‘ return the provider
Public Shared Shadows Function Instance() As DataProvider
Return objProvider
End Function

#End Region

#Region “Abstract methods”

‘ …
Public MustOverride Function
GetHtmlText(ByVal moduleId As Integer) As IDataReader
‘ …

#End Region

End Class

 
New Post
1/21/2012 8:49 AM
 
Dnn uses a provided model that allows late binding of classes at run time. On one end of the data provider there are a set of stubs or placeholders - these are linked at runtime with the actual classes that do the data access work.

 
New Post
1/21/2012 10:04 AM
 
Thanks Wes,

I believe I understand late binding, and the provider model, but don't understand how that explains a class referencing itself. How can a class reference itself before it has even been fully instantiated?

Chris
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Getting StartedGetting Starteddataprovider class seems to reference itselfdataprovider class seems to reference itself


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out