MEF Enabled Web

The web sample adds MEF functionality that enables custom UserControls to communicate with the parent page and with each other. Just to make the point clear one of the two UserControls is created in a separate project. The UserControls are loaded at runtime into the page and since MEF is present the page and controls export and import to connect to each other. Suddenly button clicks on the page makes things happen on the UserControls.

How the sample enables MEF

  • The Web Application project is integrated with Unity that builds up each Page and UserControl upon each request.
  • A custom HttpApplication class (MEFHttpApplication) adds a UnityContainerExtension to the initialization sequence.
  • The UnityContainerExtension (MEFContainerExtension) configures a custom BuilderStrategy in the Unity setup phase.
  • The BuilderStrategy (MEFStrategy) adds any instance to the MEF composition service thus enabling MEF in the Web Application.

The sample

  • The single Page (default.aspx) in the sample dynamically loads two UserControls into the page.
  • Buttons on the page sets colors to the UserControls.
  • Communication between the Page Buttons and the UserControls is handled through MEF.
  • The second UserControl on the page was not created in the Web Application. It was dropped into the Web Application but created in a separate project.
  • The second UserControl imports a contract exported by the first UserControl. This enables the second UserControl to communicate with the first one through a Button.

Projects in the sample

(MEF Web.sln)

MEF.Web

The framework project for the solution that contains the contracts and also the extensions to Unity and ObjectBuilder2 needed to enable MEF in the application.

MEF Enabled Web

The main sample that shows a web page with an import.
This is the startup project.

Web Extension 1

A project that defines a UserControl that is separate to the web application.

MEFTests

The tests.

Requirements

The sample uses Unity 1.1 (that uses OjectBuilder2) to enable Dependency Injection in the application. It also uses a custom MEF Strategy added to the ObjectBuilder2 chain of strategies to be able to add MEF to the application.

Super Simple MEF Web

A new project which strips down MEF to its most basic implementation. A perfect start to get your head around the core benefit of MEF before you delve into the goodies of split assemblies and so forth.

Super Simple MEW Web with AJAX on the top

A revision of the previous project but this time with update panels.

Last edited Oct 25, 2008 at 1:41 PM by henrikweimenhog, version 2

Comments

cooplarsh Feb 11, 2010 at 8:34 PM 
I was looking for the MEF Web.sln (or the other web projects you mention) but wasn't able to find it. Is it part of the 0.8.1.1 mef contrib build, or should I be looking elsewhere?