ASP.Net MVC Portable Area – Part 4 IoC framework support.

This is a multi post series on ASP.Net MVC Portable Areas

Using an Inversion of Control Container is a common scenario that would be needed by a Message Handler.  The Bus has an extensibility point to create the handlers. The model for this should feel similar to the ControllerFactory extension point in the ASP.Net MVC framework.  The sample below shows how to create a Message Handler factory for the StructureMap framework.

 

image

 

The SetMessageHandlerFactory method should be called once at application startup.   Other than that … this is a pretty simple way to add a Dependency Injection Framework support to the Portable Area infrastructure.

 

This makes it pretty simple for your message handlers to use constructor injection to manage their dependencies.

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Eric Hexter

I am the CTO for QuarterSpot. I (co)Founded MvcContrib, Should, Solution Factory, and Pstrami open source projects. I have co-authored MVC 2 in Action, MVC3 in Action, and MVC 4 in Action. I co-founded online events like mvcConf, aspConf, and Community for MVC. I am also a Microsoft MVP in ASP.Net.
This entry was posted in Asp.Net, Asp.Net MVC, Portable Area. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://www.lostechies.com/members/bogardj/default.aspx bogardj

    I wonder if there’s a way to do away with all the Factory classes by just standardizing on CSL….

  • http://www.lostechies.com/members/erichexter/default.aspx erichexter

    @jbogard, That is certainly an option.. We have talked for some time about putting CSL into mvccontrib and adding a CSL ControllerFactory.. this would be the same thing.. where the default CSL does the Activator .CreateInstance… On the other hand we have followed the conventions that are already baked into the MVC framework. So having mvccontrib be consistent with the MVC framework has value as well.

  • http://www.joshua-arnold.com Joshua Arnold

    Eric, this is a huge step in reusability for MVC. Kudos to the ASP.NET MVC team for including Areas and great contributions by you and Headspring!

    I have a handful of MVC applications that require a “widget” like infrastructure. Rather than reinventing the wheel, I’m working on some modifications to this to do so. Would love to talk with you about some of our ideas.