Forum


HomeHomePremiumPremiumDevelopmentDevelopmentCode Reuse In ModulesCode Reuse In Modules
Previous
 
Next
New Post
9/6/2013 4:16 PM
 

Hello DNN Hero and thanks for the video tutorials.  Sorry if this has been answered or if this is obvious, I am just getting my feet wet with module development.

I am working on a website that will be reusing product data in various places.  I have a database that contains all the product data.  I have objects that are used to interact with the database doing all the CRUD and would like to know the best way to use these in multiple modules.  For example I may create a Product List module and a Product Details module that would both use my Product object to retrieve data.  To simplify data entry and in an effort to minimize duplicate data storage, I plan to store the product ID in the module and load the product details from the database using my product objects on page load.

What is the best way to reuse code in multiple modules?  Specifically, if possible, I would like to avoid the situation of needing to recompile multiple modules because a new piece of data is added to the product object.  Does anyone have any tips for me?

 Thanks

 
New Post
9/7/2013 5:28 AM
Accepted Answer 

Andy,

 When I architect modules, one of the things I look at when determining how they are packaged and the domain data that they will use.  In my tutorial on Module Views and Navigation, I show how you can create multiple module views in a single module definition.  Those views will be in a single project, will share a common data access layer, and will be packaged together as a single module.

But you can also create a single Visual Studio project that has multiple views AND multiple module definitions (meaning multiple module extensions for users to drop on a page).  These modules can still be installed as one package and use a common assembly which has your data access layer.

 The way to do this is to include two package elements in your DNN manifest, each having a unique module name and module definitions, but sharing the same assembly. It looks like this:

<dotnetnuke version="5.0" type="Package">
    <packages>
        <package name="Module 1" type="Module" version="00.00.01">
            <friendlyname>Module 1</friendlyname>
            ...
            <components>
                <component type="Module">
                    ...
                </component>>
                ...
                <component type="Assembly">
                    ...
                </component>
            </components>
        </package>
        <package name="Module 2" type="Module" version="00.00.01">
            <friendlyname>Module 2</friendlyname>
            ...
            <components>
                <component type="Module">
                    ...
                </component>>

            </components>
        </package>
    </packages>
</dotnetnuke>


If you really need your module projects broken up into different Visual Studio projects, then another way to do this is to create a Class Library project and just put you DAL code in there. Then you can reference that common library in all of your module projects.

Hope this helps!
Scott
 
New Post
9/11/2013 10:16 AM
 

It looks like this is exactly the info I need and you cover the available options well.  I am working on a few other parts of the project right now and will follow up here once I get back on this if I have anything useful to add.

 Thanks.

Andy

 
Previous
 
Next
HomeHomePremiumPremiumDevelopmentDevelopmentCode Reuse In ModulesCode Reuse In Modules



Try FREE
30 days money back guaranteed