This project is read-only.

Best way to handle module DLL dependencies

Topics: Customizing Orchard, General, Writing modules
Jun 27, 2011 at 5:40 PM

What is the best way to handle module dependencies without blowing up the site?  Here's the behavior I'd like to accomplish.  Say I have Module1 and Module2.  Module1 has two features, Feature1 and Feature2.  Module1.Feature1 is the default functionality, and should be able to be enabled without Module2.  Module1.Feature2 is dependent on Module1.Feature1 as well as Module2.  So I have a project/dll reference to Module2 in Module1's project.  If I don't include the DLL for Module2 in Module1's code, then I think it will blow up when you enable Module1, even if you don't enable Module1.Feature2 if you don't have Module2 installed. I don't mind including a DLL for Module2 in Module1, as long as it's just for compilation purposes and will never actually be used.

I hope this makes sense.  Just wondering how to achieve this functionality.

Jun 27, 2011 at 7:11 PM

It makes sense to me because I have the same question. I have a module that adds some user functionality. This module defines my ContentPart classes. Then, I have a separate module that adds some special administrative functionality. I would like the second module to be able to reuse those ContentPart classes, as well as some custom business logic classes of my own creation. How can I get my admin module to use the ContentParts and other classes defined in my main module? Anyway, I just thought I would add my +1 to your question.

Jun 27, 2011 at 7:16 PM

Yours is a little bit of a stripped down version of my situation, as your Module2 is dependent on Module1.  Mine is slightly more complex in that one feature is dependent, but another feature is not. 

Jun 27, 2011 at 8:19 PM

I'm sorry but I don't see a question here. Can you please restate it? I mean, it seems like you have both found how to add a dependency, so what problem exactly are you facing?

Jun 27, 2011 at 8:24 PM

How do you go about deploying a module that is optionally dependent on another? In my example, assume an end user wants Module1.Feature1 but not Module1.Feature2.  So they shouldn't need to install Module2.  I'm not 100% sure about this, but I *think* if they try to install Module1, they will get a big error because Orchard can't find the Module2 DLL (even though it's not necessary).  Is this correct?  

The workaround would be to include a copy of Module2's DLL, but I wasn't sure if Orchard would load the correct DLL in the case that they were both installed.

Jun 27, 2011 at 8:26 PM
Edited Jun 27, 2011 at 8:27 PM

Oh, I see. You create a module recipe in module 1 that installs the dependency module. When people install from the gallery, they will be prompted to execute the recipe. One day, we'll also have standalone recipes in the gallery.

Your users will have to install the dependency, there is no way around that. They don't necessarily have to enable all the features though.