Register | Login
Friday, August 29, 2008

Sections
  
About Us
  
Hosting Provided by Server Intellect
Partners
Downloads
  
 WWWCoder.com Resource Directory

 

ORDER TODAY!
Professional DotNetNuke ASP.NET Portals
Amazon.com now has the only DotNetNuke book you'll ever need. Written by the guys who brought you DotNetNuke, Shaun Walker, Patrick Santry, Joe Brinkman, Dan Caron, Scott McCulloch, Scott Willhite, and Bruce Hopkins. Order it now! .

DotNetNuke (DNN) 2.x Module Architecture, Part I
5/10/2004 10:27:33 PM

In this article we go over the architecture of a DNN 2.x module, specifically the Survey module example included within the DotNetNuke distribution. In part one, we cover setting up a development project, and the user interface for our module.

If you're not familiar with DotNetNuke, be sure you visit http://www.dotnetnuke.com to learn more about this fast growing open source portal that you can use and develop against absolutely free.

DotNetNuke (DNN) has been out now for a little over a year and has really seen a tremendous amount of growth. The community is a very active and large community, which can easily be demonstrated by viewing the activity in the ASP.Net forums. In this article we will cover module creation for DotNetNuke, and specifically look at the Data Provider Model of DNN 2.x. We will not get into a step by procedural method of developing modules, but rather provide you with an overview of the architecture and starting point for developing your own custom modules for DNN.

What Are Modules?

Modules provide developers with the ability to extend the functionality of DotNetNuke. DotNetNuke provides a pluggable framework that can be expanded by the development of modules. A module container is provided by DotNetNuke to host a custom module. Modules can be developed in any .NET language, even though DNN is developed in VB.NET, a C# developer can still create a module that plugs into the core framework provided by DNN. This pluggable framework is accomplished by creating compiled private assemblies that expose and utilize interfaces specific to DNN. Once you compile the assembly, then just create a UI in the form of ascx files that allow your user to interact with your module.

Module Containers

Module containers provide several features for you as a developer. Besides being your way of interfacing with the DNN core framework, module containers also provide the following:

  • Security mechanisms: You can define view and edit permissions for your modules. DNN will then handle the security checking for your module. You do not need to write your own security mechanism, rather use the role based security provided by the framework.
  • Look and feel: Module containers can be customized with various looks, in addition the module container and DNN provide you with the ability to place the module within the DNN page. In addition, it also allows your users to customize the appearance of the module as well, for example minimize and maximize modes.
  • Caching: As a performance mechanism you can define caching at the container level. This allows modules that do not need to be updated on every request to have their contents cached thus providing a performance improvement.

Configuring Your Development Environment

Now that we covered what modules actually are, lets go on and create a development project for our module. There are various methods for creating modules for DNN, but we prefer to configure a separate project for module creation and then compile the assemblies within the DNN bin folder. The following procedure  provides a method for configuring a portal module project in Visual Studio.NET.

  1. Create a new class project, be sure to use a logical naming structure. For example: CompanyName.ModuleName.
  2. When creating the new project folder, create a folder off of the DotNetNuke Root\DesktopModules\ directory.
  3. Clear any namespace from the project properties. Right click on properties of the project, under general clear the root namespace box.
  4. Add a reference to the DotNetNuke project in your new module project.

That's it for the base module assembly project. Now if you want to add a data provider assembly to your project you would follow the same procedure above except name your project CompanyName.ModuleName.SQLDataProvider (or Access depending on which database you're supporting). In addition to creating a reference to the DotNetNuke project, create a reference to your main module project and also the Microsoft.ApplicationBlocks.Data assembly. This is going to aid in the data abstraction.

Once you're project is done, it should look like the following in the solution explorer in Visual Studio.NET:

Figure 1.1 Solution Explorer View

Now let's first cover a little architecture for DNN. The following diagram is taken from the DotNetNuke documentation. This provides a look into how DNN is architected. First with the ascx controls which provide our user interface. The interface then communicates with the Business Logic Layer (BLL), as in the diagram this BLL is contained with the SurveyDB.vb class, and provides all data for our user interface. Below the BLL we have the Abstract Data Provider, we'll get more into this later, but this class provides an abstraction layer for our application. This provider is not database specific, rather our data provider class will provide methods that override the abstraction class and interaction with our specific database. The abstraction provider in this example is the DataProvider.vb class within the main survey module project. Below the abstraction layer we have our Data Access Layer, this class is specific to a vendor database and is unique based on what database we want our module to interact with. This class is the SQLDataProvider project as in the image above. Finally there is the Microsoft.ApplicationBlocks.Data which provides functions for our specific database interaction, and frees a developer from having to write specific SQL Server code.

Figure 1.2 DotNetNuke Architecture

Now that we covered project creation and architecture, let's get started writing some code. All code referenced in this article is the survey module example provided with DotNetNuke, so you can try it out for yourself.

Create Your Controls

First we need to create some controls for our user to interact with. In this example we have a Survey.ascx control, this control is the primary survey control that is public ally viewable for the user. The other controls are for managing the survey, these are the EditSurvey.ascx, and EditSurveyOptions.ascx controls.

View Control

In the view control, this is the main Survey.ascx control, open the code behind file. In this class you'll notice the following: 

Imports DotNetNuke
Namespace YourCompanyName.Survey
    Public MustInherit Class Survey
        Inherits PortalModuleControl
        ::
        ::
End Class

You'll notice instead of inheriting from the WebControls class, the module inherits from the PortalModuleControl provided by DNN. The PortalModuleControl, located in the /components/desktopcontrols.vb class, provides some very important properties and methods exposed by DNN, for example:

  • IsEditable: Property determines whether or not the current user has edit permissions for the module.
  • UserId – id of the current user
  • Help File path – file path to help
  • Portal alias – the alias or name.
  • Portal ID – the current portal id
  • Tab ID – id of the current tab within DotNetNuke
  • Module ID – id of current module
  • Settings hash – similar to a registry for storing module specific values.

In this specific example, we have a some basic interaction with a database via the BLL. Remember the entire code for this module is available in the DotNetNuke download as example of custom module development. Use this as a template for your own projects.

Edit Control

Now that we went over the view control, most modules have at a minimum of two ascx controls, one for the view which the user sees, and another control for editing certain features of a module. This edit control provides you with a way of customizing a module for each instance within your DotNetNuke portal. For example, in the survey module you may want to create multiple surveys for your portal. You can do this by passing specific values to the module via the edit control. The DNN framework provides this by keying off of the ModuleID provided by the PortalModuleControl, as well as a Settings hash table, which is similar to a registry for storing module specific information.

Let's take a look at storing and retrieving values to the settings hash:

Private Sub cmdUpdate_Click(ByVal sender As Object, _
 ByVal e As System.EventArgs) Handles cmdUpdate.Click
   Dim objModules As New DotNetNuke.ModuleController
   objModules.UpdateModuleSetting(ModuleId, "surveyclosingdate", txtClosingDate.Text)
   objModules.UpdateModuleSetting(ModuleId, "surveygraphwidth", txtGraphWidth.Text)
   ' Redirect back to the portal home page
   Response.Redirect(NavigateURL())
End Sub

You'll notice in the Click handler above, we write some values to the settings hash for this specific module. We specify the ModuleID, which is provided by the PortalModuleControl, and then store the text field values within the hash. It's a pretty easy thing to do, only a couple lines of code. Retrieving information from the hash table is just as painless:

txtClosingDate.Text = CType(Settings("surveyclosingdate"), String)
txtGraphWidth.Text = CType(Settings("surveygraphwidth"), String)

Above we do the opposite of the above and retrieve the values from the hash table and populate our text controls.

Letting DotNetNuke Know About Your Modules

Many of you may be familiar with Private Assembly installation files, here you just upload a zip file to DNN and everything is installed automatically. When you're developing modules you usually have to do this process manually, and let DNN know where your ascx controls are. Your compiled assemblies are already being compiled and placed in the DNN bin folder so DNN can access them when needed, but you still need to let DNN know about your new module. You can manually define your modules using the following procedure:

  1. Under Host Settings menu, go to Module Definitions
  2. In Module Definitions Select Add New Definition from the module menu in the upper left hand corner.
  3. You will then be presented with the Edit Module Definitions screen.
  4. From here add a new definition.
  5. Once your definition is created, then add your user controls to your module. For the survey module you will need to add the following:
    • Survey.ascx - Type of View
    • EditSurvey.ascx - Type Edit, Key is Edit.
    • EditSurveyOptions.ascx - Type is Edit, Key is Options.

Creating the Database Structure

Now that DNN knows about the Survey module example, you will want to create the database structure. If this is a private assembly install you could just install the assembly, but to play it safe for a development project it is best to run the SQL script manually. I prefer to run the script in Query Analyzer in the SQL Server tools menu. First you need to open the script which is located in the SQLDataProvider folder for the Survey module. Then remove the {databaseowner} and {objectqualifier} directives from the script; a simple search and replace in notepad will take care of this. These directives are for DNN when installing your module as an assembly file. Once you remove these directives, execute the script to generate your database manually.

Referring to Your Module Keys

On a final note of this part in the module creation series, we will cover referring to your control's keys within the code. Open the survey example, and expand the initialize method in the code behind of the survey.ascx control. You'll notice here where the module creates the menu options for each of the controls:

' PortalModuleControl base class settings for this module
MyBase.HelpFile = "help.txt" ' a local document stored in the same folder as the user control
MyBase.HelpURL = "http://www.dotnetnuke.com" ' a URL for support on the module
' action menu items
MyBase.Actions.Add(GetNextActionID, "View Options", "", URL:=EditURL(, , "Options"), _
  secure:=SecurityAccessLevel.Edit, Visible:=True)
MyBase.Actions.Add(GetNextActionID, "Add Survey", "", URL:=EditURL(), _
 secure:=SecurityAccessLevel.Edit, Visible:=True)

Here we create the menu options, and then refer to them by their key. For example, look at the MyBase.Actions.Add method, we add our menu options and refer to them by Key in the final value sent to he EditURL. You can see "Options" being passed. This is the key we defined earlier in our module definitions. We also specify security information for the menus as well.

Hopefully this article will provide you with an informative overview of the architecture of the Survey module that comes packaged with DNN. Use this example to build your own modules with. In the next series of module architecture we will discuss the data provider model of DotNetNuke and how you develop against it.

By: Patrick Santry, Microsoft MVP (ASP/ASP.NET), developer of this site, author of books on Web technologies, and member of the DotNetNuke core development team. If you're interested in the services provided by Patrick, visit his company Website at Santry.com.

Related Articles
   Related Document DotNetNuke (DNN) 2.x Module Architecture, Part III
   Related Document DotNetNuke (DNN) 2.x Module Architecture, Part II


Page Options:
format for printing  Format for Printer
email article  Email Page
add to your favorites   Add to Favorites
How would you rate the quality of this content?
Poor - - Excellent
Comments?
Overall Rating:
Comments Left:
Left on 5/28/2008 5:13:12 AM by Anonymous
Comments: Can include screenshots and downloadable version. Must give more details
Left on 11/11/2007 7:52:46 PM by Anonymous
Comments: Hello! Good Site! Thanks you! luuyzdumjzqjt
Left on 6/7/2007 9:56:25 AM by Anonymous
Comments: Not able to print
Left on 4/20/2007 3:56:47 AM by Anonymous
Comments: hopeless articles for those who are new into DNN
Left on 3/1/2007 5:21:26 PM by Anonymous
Comments:
Left on 1/23/2007 2:21:58 PM by Anonymous
Comments: why?
Left on 6/16/2006 12:20:12 PM by Anonymous
Comments: This is not what iam looking for
Left on 8/20/2005 3:54:55 AM by Anonymous
Comments: About OOP and 3-layer I think "survey" it self is were is located the BBL where the DNN is the presentation layer. I really do not see from where came the non-OOP orientation that see some of the comments.
Left on 8/20/2005 3:21:09 AM by Anonymous
Comments: Definitivly a very helpful and strait forward explanation not only of the architecturte but also of the container-control and files distubution of DNN module. I am used to go starit to the source code and understand what software components do. Now I assured I have understand it adecuatly. Thanks
No ratings available.
Left on 7/3/2005 11:01:03 PM by Anonymous
Comments: I frankly didn't learn anything from this documentation. As a user just mentioned in his comments, I managed to pick up concepts using the traincert videos in 10mins flat. this document needs to be totally revamped and made more 'user-friendly' and comprehendable.
Left on 6/17/2005 9:58:50 AM by Anonymous
Comments: can anyone explain the difference between each type control and what the key is used for. Thxs
Left on 5/28/2005 7:06:29 AM by Anonymous
Comments: not very good
Left on 5/14/2005 9:06:40 AM by Anonymous
Comments: This article could be expanded significantly. It doesn't adequately explain the module creation procress. I don't understand why, if there is a zip mechanism for creating modules, that this article says to compile directly as part of the project.
Left on 2/24/2005 4:38:34 AM by Anonymous
Comments: You don't mention that you need Visual Studio Pro or higher to add a class library
Left on 2/15/2005 3:18:44 AM by Anonymous
Comments: its really very vague
Left on 1/14/2005 10:56:44 AM by Anonymous
Comments: The resource is very vague. Hate to be negative but this article was of little value.
No ratings available.
Left on 12/11/2004 4:09:53 AM by Anonymous
Comments: Comments from the following blog: icfarmer, located at: http://www.cnblogs.com/icfarmer/archive/2004/12/11/75637.html
No ratings available.
Left on 11/24/2004 2:28:28 AM by Anonymous
Comments: Newbie comment - I fail to see how these modeules intercommunicate. For example on http://www.iRateRides.com I have a select make model year control that has to communicate with the catalog object. How do you do inter-module communication?
Left on 11/6/2004 6:17:56 AM by Anonymous
Comments: I prefer the training videos from dotnetnuke.traincert.net. I learned these things in less than 15 minutes.
Left on 10/25/2004 5:35:59 PM by Anonymous
Comments: fgfgf
No ratings available.
Left on 10/20/2004 9:25:32 AM by Anonymous
Comments: i think u will find the code for the survey module in the ./desktopmodules/survey/
No ratings available.
Left on 10/12/2004 3:06:47 PM by Anonymous
Comments: Once your definition is created, then add your user controls to your module. For the survey module you will need to add the following:
Survey.ascx - Type of View
EditSurvey.ascx - Type Edit, Key is Edit.
EditSurveyOptions.ascx - Type is Edit, Key is Options.
???How these files are actually associated with the module????
Left on 10/12/2004 3:04:46 PM by Anonymous
Comments: Very general description. A lot of details are missing so the article is very hard to follow for the new person. I find it almost useless.
No ratings available.
Left on 9/23/2004 12:52:40 PM by Anonymous
Comments: Comments from the following blog: WDevs Admin Blog, and lots of other stuff, located at: http://blogs.wdevs.com/am/archive/2004/09/23/626.aspx
No ratings available.
Left on 9/12/2004 10:47:11 PM by Anonymous
Comments: Comments from the following blog: Paeceb, located at: http://peaceb.dyndns.org/blogx/archive/2004/09/13/181.aspx
No ratings available.
Left on 9/12/2004 10:47:07 PM by Anonymous
Comments: Comments from the following blog: Paeceb, located at: http://peaceb.dyndns.org/blogx/archive/0001/01/01/181.aspx
No ratings available.
Left on 8/29/2004 12:39:40 PM by Jeremy Heckathorn
Comments: I can not find the Microsoft.ApplicationBlocks.Data reference. I always have to copy an existing module to use as my start. Do you have an idea why its not showing up under add references for me?
No ratings available.
Left on 8/17/2004 8:40:51 PM by Anonymous
Comments: Answer to question "how to design an ascx in class project"-The "fork" in the road between development is the battle between the class library module and the "multiple web project" solution module. See http://www.dotnetnuke.dk/Default.aspx?tabid=59 for the multiple web project tutorial and http://dnnjungle.vmasanas.net/Default.aspx?tabid=28 for a tutorial and template for class library that includes the DNN user control in Add items.
Sadly it appears the DNN community is still at odds over the best Module development environement for Visual Studio. The sample module in DNN 2.0 is in fact a class library but It does not appear that all DNN core members agree that this is the best solution.
Left on 8/12/2004 9:07:20 AM by Anonymous
Comments: I don't know how to create ascx in class project. I don't understand what do you mean in your answer "...so right click add item, and manually create the file"
Left on 8/4/2004 10:50:18 AM by fastlink30 fastlink30
Comments: 'Remember the entire code for this module is available in the DotNetNuke download'
yes, but where? in wich section?
i've searched, but no luck!
Left on 7/2/2004 1:28:24 AM by Anonymous
Comments: Would you consider a more OOP design if the controller and the matching busness object were aggregated?
No ratings available.
Left on 7/1/2004 12:33:03 AM by Anonymous
Comments: Comments from the following blog: Paeceb, located at: http://peaceb.dyndns.org/blogx/archive/0001/01/01/175.aspx
No ratings available.
Left on 6/30/2004 10:46:15 PM by Anonymous
Comments: Comments from the following blog: Paeceb, located at: http://peaceb.dyndns.org/blogx/archive/2004/07/01/175.aspx
No ratings available.
Left on 6/30/2004 5:42:59 AM by Anonymous
Comments: As far as the business logic layer goes... there is no reason for the BLL not to contain "true" OOP style objects -> I think that is what the DNN design team is hinting towards. The Business components use the DAL to get to the database, but its the business component design that is the real kicker. Get that right and you're UI is really seperate, extensible and flexible.
Left on 6/28/2004 8:13:11 PM by Anonymous
Comments: The comment below highlights a common complaint I have with the MS view of OOP. I agree that this architecture and in fact the architecture promoted by MS  is not truly OOP, but is simply using objects as useful containers of related routines. True object orientation in my opinion is when the design of the software is based on modelling enties corresponding to the business model and the interactions between them. Every similar open source project written for MS platform that I have seen keeps pushing this architecture. I'd love to see a truly OOP framework, with true entity modelling, event handling and transparent object to relational based persistence.
No ratings available.
Left on 6/28/2004 2:04:56 PM by Anonymous
Comments: Of course the survey module is a very basic module used for this example, but if you look at the class as this article describes, there is the controller, and info classes which are your objects. These in turn call the data layer. It is truely 3 layered as the diagram plainly describes.
No ratings available.
Left on 6/28/2004 1:57:13 PM by Anonymous
Comments: Sorry, guys...I just don't get it.  Like so many of these Open Source projects, there is no Object-Orientation, or at least very little.  There is a "Business Logic Layer" but this merely acts as a holder for functions to store & retrieve data from the database. This is more like a Data Access Layer than a business layer.  Shouldn't the business layer have actual entity objects such as Survey, question, etc.?  Then these objects would call the data layer?  it doesn't seem to be 3 layered architecture or very OOP to me.
Left on 6/20/2004 10:33:08 PM by Anonymous
Comments: Right a class library project. How do you add it, well you're right again on that, VS doesn't like ascx files on a class library, so right click add item, and manually create the file.
No ratings available.
Left on 6/20/2004 10:31:01 PM by Anonymous
Comments: ok, I'm missing something here: if I "Create a new class project" do you mean a Class Library project type? How do you add a .ascx web control to a class library project, my VS 2003 doesn't give me that option..
No ratings available.
Left on 5/25/2004 1:10:50 AM by Anonymous
Comments: Now we're cooking with Gas!  Thanks for the knowledge dump.  I've looked everywhere for something like this!!!
Left on 5/20/2004 8:43:23 AM by Anonymous
Comments: Well done
Left on 5/13/2004 1:42:15 PM by Anonymous
Comments: In the survey folder is the SQLDataProvider project for that module. In my example I renamed to it to a proper name using the mycompanyname.modulename.sqldataprovider. I neglected to mention that in this article, thanks for the correction. But I would recommend naming your projects the way they are here in the article. P. Santry
No ratings available.
Left on 5/13/2004 1:38:34 PM by Anonymous
Comments: I have one question.  You show in Figure 1.1, the project YourCompanyName.Survey.SqlDataProvider.  However, the actual demo project provided with DotNetNuke does not provide this project.  Is this an error in the release of DotNetNuke?
  

 Latest Articles
  

 Latest News
  

 

Spotlight
Syndication

 


 


Digg This
 


DotNetNuke Platinum Benefactor

  
 

 Terms Of Use | Privacy Statement
 Copyright 2008 - Santry Technology Solutions, Box 172, Girard, PA 16417, (814) 774-0970