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...Building ExtensionsBuilding ExtensionsModulesModulesHow to write Common/Global Code Between Modules (Using Database)?	How to write Common/Global Code Between Modules (Using Database)?
Previous
 
Next
New Post
7/12/2010 11:46 AM
 
I am relatively new to DNN and web coding. I have coded 5 modules so far using C# according to the DNN MVC model and standard database access methods per the DNN MVC model. I will be writing so many modules (for my own site) that will be needing to access the same code and data from the database. I have already written a common class for the non-database globals, but I can not find models of how to handle database access in a common global. Some of what I have read indicated I will have no issues with the controller class and likely no issues with the dataprovidor, but the sqldataprovider may be an issue from what I am reading. I may not be able to have two running at once (one for the module I am in, and one for the common global). Can anyone help with some examples or a clear discussion of how I can do this? I would really like to avoid coding the same 20 routines 40 times if I can.

Thanks for your input.
Paul
 
New Post
7/12/2010 2:01 PM
 
If you are using DNN 5.x (and not 4.x) you can create a separate 'module' that is a library type (this is declared in the .dnn manifest file, instead of Module you make the type Library). This will allow you to version it just as any other DNN extension, handle data access just like a module and then you can just reference it in your other modules. If you are so inclined, you could even package the library with any of the modules

Chris Paterra

Get direct answers to your questions in the Community Exchange.
 
New Post
7/15/2010 12:19 PM
 
Chris,

I have been working on your suggestion and ran into two snags. First is the .DNN file and second is the SqlDataProvider which I will ask later. I am assuming this is an EXTENSION I should be adding (not a module), so let me know if that is wrong.

I tried Package + Library, Library + Library and finally Extension + Library and all come up as an invalid DNN file when I try to install the library into DNN using the DNN file:





Am I doing this in the right place, and if so, what should be coded in these first three lines?

Thanks,
Paul
 
New Post
7/16/2010 4:38 AM
 
Paul, if I understand what you need to do correctly, I think you can just create a Class Library type project in Visual Studio, and use it to wrap all the common functionality that you want to share between modules (for example Business Controller class(es)). Make sure that when you build the project, it copies its DLL to the bin directory of your development DNN instance.

Then, in each module, create a reference to the project (or dll in bin directory). Use as normal.

When it comes to packaging the modules, make sure the manifest includes the library dll. You need to take care with SQL Data Provider scripts at this point, because each module will depend on them, but they only need to be installed once.

There are various approaches you can take. You can make the scripts re-runnable, so that they detect if they have already been run, and don't run twice. You can package them with just one module, and make sure you always install that one. Or, you can package the library as a separate module, as suggested by Chris.


Paul Taylor
Dotcom Software Solutions Ltd
DotNetNuke, ASP.NET and SQL Server Development
 
New Post
7/16/2010 5:25 AM
 
Paul,
What you say helps. But I am going to discuss the issue further to see if you can help further. You see I understand enough about programming to write the code using models and DNN code as a guide, but some of the more deeper interfaces confuse me, so I am unable to figure them out, much less fix them. When I read on blog posts that I "would not" be able to create a common library because I would run into issues of the SqlDataProvider (or dataprovider) because each module is only allowed one in DNN, I knew I was in trouble, because I really do not understand the creation of the provider instance. I see many code examples of setting it up, and they are all very different. The one I am using now is:

Global Class:
public abstract class DataProvider
{

#region Shared/Static Methods

private static DataProvider provider;

// return the provider
public static DataProvider Instance()
{
if (provider == null)
{
const string assembly = "ZZWeb.Modules.Data.SqlDataprovider,ZZWeb.Modules";
Type objectType = Type.GetType(assembly, true, true); /////////////////<-- Line of death

provider = (DataProvider)Activator.CreateInstance(objectType);
DataCache.SetCache(objectType.FullName, provider);
}

return provider;
}

The Calling Module:
public abstract class DataProvider
{

#region Shared/Static Methods

private static DataProvider provider;

// return the provider
public static DataProvider Instance()
{
if (provider == null)
{
const string assembly = "ZZWeb.Modules.Term.Data.SqlDataprovider,ZZWeb.Term";
Type objectType = Type.GetType(assembly, true, true);

provider = (DataProvider)Activator.CreateInstance(objectType);
DataCache.SetCache(objectType.FullName, provider);
}

return provider;
}


I have already set up a module referencing the global DLL with some success. The module does in fact accesss the DLL and run pretty well until it hits the SqlDataProvider/Provider at which point it dies trying to create the dataprovider instance in the global module DLL code. You see both my module and the global will be accessing data, so both will have need to data (in some cases the same data, but in most cases different data) all in SQL Server 2008+ using DNN (version 5.4.2 or later).

I really get the feeling that the method I am using to create the instance is not flexible enough. It does not feel right, so this may be the issue I am having. If you can help, not only desribe what is wrong with the code but point me to a C# example in codeplex where this is the right code for the Controller/DataProvider/SqlDataProvider combination.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to write Common/Global Code Between Modules (Using Database)?	How to write Common/Global Code Between Modules (Using Database)?


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