tags:

views:

118

answers:

3

I have developed a plugin system that makes it easy to plug in new logic to an application. Now I need to provide the ability to easily add UI widgets.

There are already some good responses on how to create a portal system (like iGoogle) with ASP.NET MVC, and I'm fine about the overall concept.

My question is really about how we make strongly typed widgets.

Essentially when we set up a widget we define the controller and action names that are used to render that widget. We can use one controller action for widgets that are not strongly typed (since we just return PartialView(widgetControlName) without a model)

For widgets that are strongly typed (for example to an IList) we would need to add a new controller action (since I believe it is not possible to use Generics with ActionResult e.g. ActionResult).

The important thing is that the widget developers should not change the main application controllers. So my two thoughts are this:

  1. Create new controllers in a separate class library
  2. Create one partial WidgetController in the main web project and then extend this in other projects (is this even possible?) - not possible as per @mfeingold

As far as the development of the widgets (user controls) go, we can just use post build events from our extension projects to copy these into the Views/Widgets directory.

Is this a good approach. I am interested to here how others have handled this scenario.

Thanks Ben

P.S - in case it helps, an example of how we can render widgets - without using Javascript

    <%foreach (var widget in Model) {%>

    <%if (widget.IsStronglyTyped) {
          Html.RenderAction(widget.Action, widget.Controller);
      } else {
          Html.RenderPartial(widget.ControlName);
      } 
    %>

<%} %>
+1  A: 

The answer to your second question is NO. all source code for partial classes should be in the same project.

mfeingold
A: 

Is it possible with the templating engine to create a template for your widget type, then just call <%: Html.EditorForModel(untypedWidgetModel) %> - in theory, your template for that type would then take over and render appropriate HTML.

Or have I misunderstood how templating can work?

pete the pagan-gerbil
@Pete - unfortunately this will not work since widgets may have completely different view models. The only way I am aware of catering for this would be to have different controller actions for each type of widget.
Ben
+1  A: 

For me it seems that MvcContrib's portable areas fits for developing independent widgets perfectly.

Here is an example - OpenId authentication widget.

Next week You can even watch c4mvc presentation about it.

Arnis L.
@Arbis, portable areas does look like it will do the job nicely although it would be good to see how we could use an IoC container so that we can lose the dependency that the main web project needs to have on the portable area project. For example a blog feature developed as a portable area may need to perform authentication via the Bus. From the example I saw at http://cdn-static.viddler.com/flash/publisher.swf?key=81f1a688 the message handler would need to be registered in the main web application. This would mean that to "plug in" the blog feature, I need to dive into Visual Studio.
Ben
Regarding using IoC with Portable Areas - please see my solution at http://groups.google.com/group/mvccontrib-discuss/browse_thread/thread/db00b09665dcc7ac#
Ben
Your portable areas link is incorrect.
StriplingWarrior
@StriplingWarrior feel free to edit it.
Arnis L.