Using DevExpress MVC Extensions in creating Orchard Modules

Topics: Writing modules
Mar 30, 2011 at 12:04 AM

Hi,

I have DevExpress ASP.NET MVC Extensions license and I was wondering if I could use those MVC Extensions in creating modules for Orchard CMS.

I tried today to integrate those controls but I received several errors... If you look at the documentation here, http://documentation.devexpress.com/#AspNet/CustomDocument8163

they required those extensions to be registered in the web.config file. In short, here are the steps required :

  • Add reference to controls in Web.config
  • Register HttpHandler and HttpModules in Web.config
  • Register the namespaces in the Web.config
  • Register JavaScript
  • Register Themes

All those steps could easily be done in a normal MVC Application but how do we do all this in a module... I want to distribute these modules. Any body who wants to use the modules should be able to click install and be done with it. I don't want the users to register HttpHandlers and Modules...

Can anybody point me in the right direction?

 

 

Coordinator
Mar 30, 2011 at 12:15 AM

Adding references can be done in your project file. Registering script and stylesheets should be easy, using the corresponding Orchard APIs. For the namespaces you can always put using directives in your views.

The part that I'm more concerned about is the HTTP handler and module. The handler could probably be dealt with by creating a route for it. The module on the other hand I have no idea how to wire. They don't seem to provide any details about what it's doing either.

Mar 31, 2011 at 2:29 PM

It looks like registering HttpModules in the Web.Config is mandatory...

Does Orchard allow us to register HttpModules in the parent websites Web.Config file?

Coordinator
Mar 31, 2011 at 11:04 PM

It doesn't, except by modifying web.config... This might be worth a shot: http://blog.davidebbo.com/2011/02/register-your-http-modules-at-runtime.html

Apr 3, 2011 at 5:04 AM
Edited Apr 3, 2011 at 5:18 AM
bertrandleroy wrote:

It doesn't, except by modifying web.config... This might be worth a shot: http://blog.davidebbo.com/2011/02/register-your-http-modules-at-runtime.html

 

bleroy this is a cool feature of asp.net but I can't execute it inside a module. The way it works for me is inside Orchard.Web.

Apr 3, 2011 at 3:43 PM

I'm guessing the PreApplicationStartMethod won't work because your dll isn't loaded at application start, Orchard loads it dynamically later.

But it could still be possible to use DynamicModuleHelper at a different point, or even to build a feature into Orchard using that technique that would allow modules to register HttpModules.

Apr 6, 2011 at 4:42 AM

The DynamicModuleUtility.RegisterModule Method can only run on PreApplicationStart. If you try in a module generate errors.

I'ld really like to use devexpress controls in orchard modules. Any suggestions?

Coordinator
Apr 6, 2011 at 4:47 AM

You will either need to modify the root web/config or to ask DevExpress to build a version of their controls that works in Orchard. Or contribute or file a suggestion to provide a hook for modules to register http modules, but that may not even be technically possible and if it is it may take a while. Really, DevExpress building an Orchard module looks like the easiest option.

Apr 6, 2011 at 5:14 AM

bleroy take a look what devexpress suggests with inheritInChildApplications="false" in web.config here: http://www.devexpress.com/Support/Center/p/Q315224.aspx.

Have to try it.

Coordinator
Apr 6, 2011 at 5:19 AM

Sorry, but I don't understand how that solves anything.

Apr 6, 2011 at 9:28 AM

I think they are getting confused over the difference between deploying an Application in a sub-folder vs. MVC area which happens to have its own Web.config - these are two totally different things.

I'm not sure what devexpress is requiring HttpModules for, but with Orchard you can use a FilterProvider / IRequestFilter to wrap around the request for most scenarios that a HttpModule would typically be used for. Unless they're doing something extremely funky in their HttpModule this should be possible, but it boils down to whether they're prepared to do an Orchard release.

I'd honestly look for something open source that provides the functionality you're after if you want to build something that can be distributed as a module; so you can do your own integration if needed. Since devexpress requires a license it's not exactly something you could easily distribute anyway...

Aug 5, 2011 at 5:02 PM
Edited Aug 9, 2011 at 3:23 PM

The solution I have found till now is to create a class library project and a class in it with only this 

        public static void Start() {
            Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule));
        }

then edit the AssemblyInfo.cs and add 

[assembly: PreApplicationStartMethod(typeof(Orchard.Devexpress.PreApplicationStartCode), "Start")]

where Orchard.Devexpress is the namespace and PreApplicationStartCode is the class.

Compile and put the dll in bin directory of Orchard.Web project.

Hope that helps.