MEF and ASP.NET MVC sample updated

Sample updated to Preview 6. I've also took the time to simplify the MvcCatalog and to hard set the Creation Policy to Non Shared for all controllers.

Have fun!

Comments (8)

  1. Juliën says:

    Excellent! Was looking for a sample that worked around the (now) obsolete metadata in the GetExports function (CreateController).

  2. Tom says:

    Thank you for the article and sample code.  I’m feeling my way through it.  I noticed the views in your Extensions class are not strongly typed.  Instead, you are populating ViewData dictionary using magic strings:

    ViewData["forums"] = _forumService.GetEnabledForumsRecentActivity();

    Can we use strongly types views in the Extension classes?  I hates using magic strings and dictionaries I do.  Anyways, thanks for your efforts.

  3. Mike says:

    Great code, that is what i was looking for.

    But it seems, that it doesn't work with MVC 2 and MEF Net 4.0

    I get the following error message after refreshing a page:

    A single instance of controller 'xxxController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request.

    GetExports() does not return a new instance, even if the controller is decorated with [Export, PartCreationPolicy(CreationPolicy.NonShared)].

    Is there any workaround for this, i would like to use this approach so much in my current project.

    Thanks a lot.

  4. @Tom,

    I'm sure you can. It should work as it's no correlation with MEF.


  5. Richie Scott says:

    I agree with Tom, it doesn't work when the view is strongly typed…any ideas?

  6. Did you try with the very latest version of the sample?

  7. Sasha says:

    How to add another function to controler (wiki ext. as  sample)

    public ViewResult RSVPForm()


               return View(ViewRoot + "RSVPForm.aspx");


    and then call it in index.aspx  <%= Html.ActionLink("Go to reg form", "RSVPForm")%>

    Thanks, and sorry for my bad english

  8. vcshaman says:

    Hi, thank you for the good article 🙂

    I have one question. How i can change plugin loader to force it load plugins without add reference to main web app.

    When i change var assembly = Assembly.LoadFrom(fileName) to  Assembly.LoadFile

    i got some trouble with partial view in Forum plugin…

    Thanks a lot

Skip to main content