DynamicModuleUtility

Monday, February 28, 2011

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.


Comments
gravatar Ricardo Peres Tuesday, March 1, 2011
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 scott Tuesday, March 1, 2011
@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 Ricardo Peres Tuesday, March 1, 2011
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
Slappy Thursday, April 7, 2011
I wander if you can use it with MEF to dynamically wire up modules with imports? Probably not
gravatar Kristian Ask Thursday, April 28, 2011
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 scott Sunday, May 1, 2011
I don't think it has that capability - I think that's something you
could use stuff inside of System.AddIn to do.
gravatar Sam Thursday, May 5, 2011
@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 scott Saturday, May 7, 2011
@Sam:

That should be available soon (a deployment module).
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!