DynamicModuleUtility

One of the interesting side-effects of installing ASP.NET MVC 3 is the appearance of Microsoft.Web.Infrastructure in the GAC. Inside the assembly is a DynamicModuleUtility class that will let you do the following:

using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;

[assembly:PreApplicationStartMethod(typeof(MyAppStart), "Start")]

public class CoolModule : IHttpModule
{
    // implementation not important 
    // imagine something cool here
}

public static class MyAppStart
{
    public static void Start()
    {
        DynamicModuleUtility.RegisterModule(typeof(CoolModule));
    }
}

The significant line of code is the line with RegisterModule. The DynamicModuleUtility will let you install an HTTP module into the ASP.NET pipeline without making any changes to web.config file. Registration must occur during the pre application startup up phase, so you'll probably mix dynamic modules with WebActivator for maximum flexibility. The ability to dynamically register modules opens up some interesting options for plugins and infrastructure libraries.

Print | posted @ Monday, February 28, 2011 9:12 AM

Comments on this entry:

Gravatar # re: DynamicModuleUtility
by Ricardo Peres at 3/1/2011 11:22 AM

Hi!
I can't find the Microsoft.Web.Infrastructure assembly nowhere. It isn't in the GAC, the Program Files\Microsoft ASP.NET\ASP.NET MVC 3 folder and it isn't in the source files at CodePlex!
Thanks,
RP
  
Gravatar # re: DynamicModuleUtility
by scott at 3/1/2011 11:52 AM

@Ricardo: Try Program Files \Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies. I thought asp.net web pages were installed as part of the mvc 3 install, at least the rtm version of mvc 3, but I could be wrong.
  
Gravatar # re: DynamicModuleUtility
by Ricardo Peres at 3/1/2011 1:53 PM

Hello, Scott!
Thanks for your quick reply! Indeed, they are installed with MVC 3, I just hadn't noticed this folder. Thanks for the post and the information!:-)
RP
  
Gravatar # re: DynamicModuleUtility
by Slappy at 4/7/2011 12:16 AM

I wander if you can use it with MEF to dynamically wire up modules with imports? Probably not
  
Gravatar # re: DynamicModuleUtility
by Kristian Ask at 4/28/2011 5:59 AM

Hello Scott,

You know if it's possible to use this type of implementation to load assemblies into a new AppDomain to not restart the application?

K
  
Gravatar # re: DynamicModuleUtility
by scott at 5/1/2011 8:24 PM

I don't think it has that capability - I think that's something you
could use stuff inside of System.AddIn to do.
  
Gravatar # Microsoft.Web.Infrastructure assembly
by Sam at 5/5/2011 10:17 AM

@Scoot : thanks for the assembly path (\Microsoft ASP.NET X86\ASP.NET Web Pages\v1.0\Assemblies). I couldn't find Microsoft.Web.Infrastructure either. I also found all the other assemblies missing (System.Web.WebPages ...) in this folder too. :)

PS : great courses you have at Plural Sight. The only thing missing is how to go from VS 2010 dev environment to production environment concerning Entity Framework Code First.
  
Gravatar # re: DynamicModuleUtility
by scott at 5/7/2011 6:00 PM

@Sam:

That should be available soon (a deployment module).
  
Comments have been closed on this topic.
Scott Allen
Posts - 869
Comments - 4493
Stories - 14