Los Techies : Blogs about software and anything tech!

ASP.Net MVC Portable Areas via MvcContrib


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

 

What is a Portable Area?

A Portable Area is a set of reusable multi page functionality can be dropped into an application to provide rich functionality without having to custom build functionality that is literally the same in every application. This could be considered a plug-in or add-in type of functionality.  The portable portion of this approach is that the area can be distributed as a single assembly rather than an assembly and a host of other files, like views or other html assets that need to be managed and maintained over time.  By making a portable area totally self contained in a single assembly, this should allow for easier reuse and upgrades to the area.  The challenge for doing something like this has been how do you allow enough control over the User Interface by the application yet still allow the actual views to be packaged with the logic.

Why Now?

There has been some discussion in the past on the MvcContrib mailing list about creating an plug-in framework and plugins but I do not think we had enough of the pieces in place to do this properly.   I believe that with MVC 2 we have those missing pieces figured out.  The first enabler is the inclusion of Areas into the MVC 2 feature set. This includes having the Area and Controller namespace become part of the route data which is used both for Controller/Action selection but this also flows down to the selection of a view. The second enabler is some of the work that came out of MvcContrib and the Input Builders.  While implementing that feature we came up with a way to pull views from an assembly as an embedded resource.  This with the ability to override the default view engine in a way that allows an application developer to place their own version of a view in a folder so that they have the option to change the view to their needs was huge.  The last enabler really comes from what we have learned from all of the SOA greats and see how frameworks like nServiceBus and MassTransit have demonstrated that a messaging approach for integration can keep our concerns separated.

The other why now is that my company, Headspring, has found that in order to make our practice more successful, we need the ability to drop in some of the essentials for an application, we would prefer to do this in a binary form that is easy to upgrade and does not leave us with copy and pasted code between our various projects.  We would like to see that if we learn something from one project that we have the potential to apply those learning's to projects that are still in flight. We all prefer that rather than waiting for the next project to start so that we can apply what we have learned to the new project.  This approach will be much better for us as developers and our client will benefit as well.  We could take the approach of working on this in a bubble but by putting this out for the community we can learn from every else and potentially help others in the process and raise the collective bar for the industry, in our own little way.

 

Logical View of a Portable Area

Below is a logic view of a Portable Area.  It shows how the Green block is an application.  Inside the application the blocks in dark blue are framework components in ASP.Net MVC 2 and MvcContrib.  These blocks provide some minimal framework support for registration view resolution and communication between the application and the portable area.  The light blue blocks represent code the developer create.  The code in the Portable Area is created by the Portable Area developer. The code in the application block is coded by… you guessed it. The application developer.

image

Thanks for the Pictures but where is the code?

The code is currently available in the MvcContrib MVC 2 Branch.  You can get the latest binary from our (TeamCity/CodeBetter) build server here:  http://teamcity.codebetter.com/guestAuth/repository/download/bt83/.lastSuccessful/MVCContrib.release.zip

There is a sample application you can download here: http://teamcity.codebetter.com/guestAuth/repository/download/bt83/.lastSuccessful/MVCContrib.Extras.release.zip 

or from the code repository on GitHub:  Download the source as a zip.  or Fork it on GitHub.

Kick It on DotNetKicks.com
Posted Nov 01 2009, 01:00 PM by erichexter

Comments

Twitter Trackbacks for ASP.Net MVC Portable Areas via MvcContrib - Eric Hexter - Los Techies : Blogs about software and anything [lostechies.com] on Topsy.com wrote Twitter Trackbacks for ASP.Net MVC Portable Areas via MvcContrib - Eric Hexter - Los Techies : Blogs about software and anything [lostechies.com] on Topsy.com
on 11-01-2009 1:46 PM

Pingback from  Twitter Trackbacks for                 ASP.Net MVC Portable Areas via MvcContrib - Eric Hexter - Los Techies : Blogs about software and anything         [lostechies.com]        on Topsy.com

Glenn Block wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-01-2009 2:06 PM

Nice Eric. Looking forward to seeing how the posts play out.

Martin wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-02-2009 2:14 AM

I think you should make it clear that your bus is internal (for application process) and synchrounus when you compare to NServiceBus for example.

What I mean is this:

LoginController.Index

var message = new LoginInputMessage {Input = loginInput, Result = new LoginResult()};

PortableArea.Bus.Send(message);

if (message.Result.Success)

{

 ...

}

Bus.Send would be a asynchrouns call in NServiceBus. Note, I haven't used NServiceBus but I think it works like that.

Anyhow, I will follow this with great interest.

Reflective Perspective - Chris Alcock » The Morning Brew #467 wrote Reflective Perspective - Chris Alcock » The Morning Brew #467
on 11-02-2009 3:30 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #467

Harry M wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-02-2009 5:04 AM

Is there any way to get something like this to work with MVC 1?

erichexter wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-02-2009 9:36 AM

@Martin,  Great point, by no means is this meant to do what the actual Bus projects do.  I will update the post to make that more clear.

@Harry, right now this will not work with MVC1 as it is built on top of the area implementation, but once this shakes out if there is really some barrier to upgrading from MVC 1 to MVC 2, we could look into back porting the area support into MvcContrib.  Although upgrading to MVC 2 will actually be pretty simple so, once this gets baked we could talk about why you would want to stay on mvc 1 and than what we could do to make it work on that version of the framework.

progg.ru wrote ASP.Net MVC Portable Areas via MvcContrib
on 11-02-2009 9:55 AM

Thank you for submitting this cool story - Trackback from progg.ru

Haacked wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-02-2009 2:18 PM

Does this work in Medium trust on ASP.NET 3.5 SP1?

erichexter wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-02-2009 3:52 PM

@Haacked , this approach does not work with Medium Trust. we need to get the ASP.Net team to fix that!  

Haacked wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-02-2009 7:25 PM

@erichexter it has been fixed on ASP.NET 4. Try it out!

TJ wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-03-2009 2:26 AM

Very cool Eric, i like the use of a message bus. Correct me if I'm wrong but since the portable areas are required to be referenced by the host application and then compiled, you don't get assembly drop-in functionality with this approach.  

This combined with MEF for true pluggable areas is the next step perhaps? :)

erichexter wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-03-2009 10:19 AM

@TJ, this is correct you do not get a drop in area.  But part of that reason is the way that the default area registration occurs.  In Preview 2 the area registration only scans assemblies that are referenced from the main UI application.  If this is change than the they could be drop in a bin as long as that portable area does not require some sort of communication with the host application.  If it can carry along all of its data, configuration, and logic than it could be dropped in.

Harry M wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-03-2009 4:48 PM

We're starting a new feature soon, and I've been pushing feature-based application partitioning. I don't think the powers that be will allow us to go live on a beta or CTP unfortunately, so it would be great to get this into MVC1.

There's a couple of other things I'd love to see with this, which I'm not sure this solution handles, but I would be cool if it did.

Firstly, when the parent app registers the areas, it would be nice if it could modify the routes, maybe applying a prefix to them. i.e. this means two independent areas could both use the /settings url, but the host app could choose to make the routes something like area1name/settings and area2name/settings.

The other thing is related to master pages/visual inheritance/subcontroller routing. It would be extremely neat if a master application could intercept routes registered in child areas, run them through a master controller and action in the parent, which would output containing html with a ContentPanel (like a master page), maybe register a couple of request scoped services, and then call the child area with a slightly rewritten request to produce the html to go inside the ContentPanel.

Hmm. I may need to explain myself better.

Caladin wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-03-2009 7:11 PM

I have to say this solves my biggest complaint about MVC.

Too much copy and paste of common code and all the headaches that it generates.

Thanks!

Servefault.com wrote ASP.Net MVC Portable Areas via MvcContrib - Eric Hexter - Los Techies : Blogs about software and anything tech!
on 11-04-2009 3:06 AM

Thank you for submitting this cool story - Trackback from Servefault.com

erichexter wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-04-2009 9:26 AM

@HarryM I am not sure I follow you on the Hosting Application owning the routes. I was thining that if a single area was a multi-tenant than it could add its instance to its routes.. like /{Area}/{Instance}/{Controller}/{Action}  

Right now if the Portable Apps use the same master page name this will all work out but realistically that becomes a little difficult to manage, so I was thinking that there should be a way for the application to tell the Portable Area what it should use as its master page, then the PA would be responsible for specifiing that whenever it creates a ViewResult from an action.

@Caladin,  glad to hear.. I think it has a lot of potential.

ASP.Net MVC Portable Areas ??? Part 2 - Eric Hexter - Los Techies : Blogs about software and anything tech! wrote ASP.Net MVC Portable Areas ??? Part 2 - Eric Hexter - Los Techies : Blogs about software and anything tech!
on 11-04-2009 9:28 AM

Pingback from  ASP.Net MVC Portable Areas ??? Part 2 - Eric Hexter - Los Techies : Blogs about software and anything tech!

Eric Hexter wrote ASP.Net MVC Portable Area – Part 4 IoC framework support.
on 11-08-2009 3:14 PM

Part 1 – Introduction Part 2 – Sample Portable Area Part 3 – Using of a Portable Area Part 4 – Using

ASP.Net MVC Portable Areas ??? Part 3 - Eric Hexter - Los Techies : Blogs about software and anything tech! wrote ASP.Net MVC Portable Areas ??? Part 3 - Eric Hexter - Los Techies : Blogs about software and anything tech!
on 11-08-2009 3:25 PM

Pingback from  ASP.Net MVC Portable Areas ??? Part 3 - Eric Hexter - Los Techies : Blogs about software and anything tech!

Jeffrey Palermo (.com) wrote ASP.NET MVC wins with simplicity, not features
on 11-11-2009 11:09 AM

Hot on the heals of DevConnections appearing to downplay ASP.NET MVC and folks like Dino Esposito taking notice , I want to provide my commentary on why the grassroots of the .Net developer community is so in love with ASP.NET MVC, even though Microsoft

Randy H wrote re: ASP.Net MVC Portable Areas via MvcContrib
on 11-18-2009 2:53 PM

Is there a problem with the latest version of  ASP.Net MVC 2 Beta (released 11/17/2009)? When running your MvcContrib.Samples.PortableAreas sample I am getting this error:

The view 'index' or its master was not found. The following locations were searched:

~/Areas/Login/Views/login/index.aspx

~/Areas/Login/Views/login/index.ascx

~/Areas/Login/Views/Shared/index.aspx

~/Areas/Login/Views/Shared/index.ascx

~/Views/login/index.aspx

~/Views/Shared/index.aspx

~/Views/InputBuilders/index.aspx

~/Views/login/index.ascx

~/Views/Shared/index.ascx

DotNetKicks.com wrote ASP.Net MVC Portable Areas via MvcContrib
on 12-03-2009 1:24 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Craig Shoemaker wrote 12 Ways to Simplify ASP.NET and Visual Studio
on 12-04-2009 11:15 AM

While at PDC this year I had an opportunity to interview a number of smart and engaging people. One of

12 Ways to Simplify ASP.NET and Visual Studio | I love .NET! wrote 12 Ways to Simplify ASP.NET and Visual Studio | I love .NET!
on 12-04-2009 12:15 PM

Pingback from  12 Ways to Simplify ASP.NET and Visual Studio | I love .NET!

Craig Shoemaker wrote Podcast: Portable Areas with Jeffrey Palermo and Eric Hexter
on 01-07-2010 4:34 PM

In this episode of the Polymorphic Podcast Eric Hexter ( @ehexter ) and Jeffrey Palermo ( @jeffreypalermo

Podcast: Portable Areas with Jeffrey Palermo and Eric Hexter | I love .NET! wrote Podcast: Portable Areas with Jeffrey Palermo and Eric Hexter | I love .NET!
on 01-07-2010 7:35 PM

Pingback from  Podcast: Portable Areas with Jeffrey Palermo and Eric Hexter | I love .NET!

Twitter Mirror wrote Nice article about porable areas http://www.lostechies.com/blogs/hex/archive/2009/11/01/asp-net-mvc-portable-areas-via-mvccontrib.aspx
on 02-24-2010 8:50 AM

Nice article about porable areas www.lostechies.com/.../asp-net-mvc-portable

9eFish wrote ASP.Net MVC Portable Areas via MvcContrib - Eric Hexter - Los Techies : Blogs about software and anything tech!
on 02-24-2010 8:56 PM

9efish.感谢你的文章 - Trackback from 9eFish

Multi-Project (Portable) Areas Walkthrough « Patrick Boudreaux wrote Multi-Project (Portable) Areas Walkthrough « Patrick Boudreaux
on 05-06-2010 2:14 PM

Pingback from  Multi-Project (Portable) Areas Walkthrough « Patrick Boudreaux

techBox » Pluggable MVC 2.0 using MEF and strongly-typed views wrote techBox » Pluggable MVC 2.0 using MEF and strongly-typed views
on 06-01-2010 5:13 PM

Pingback from  techBox » Pluggable MVC 2.0 using MEF and strongly-typed views

Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems