|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
namespace aspnetMEFBasic {
public partial class aspnetMEFBasic : System.Web.UI.Page {
//Import our "plugin"
[Import]
Class1 c1;
protected void Page_Load(object sender, EventArgs e) {
//Step 1:
//Find the assembly (.dll) that has the stuff we need (i.e. [Export]ed stuff) and put it in our catalog
DirectoryCatalog catalog = new DirectoryCatalog(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"));
//Step 2:
//To do anything with the stuff in the catalog, we need to put into a container (Which has methods to do the magic stuff)
CompositionContainer container = new CompositionContainer(catalog);
//Step 3:
//Now lets do the magic bit - Wiring everything up
container.ComposeParts(this);
//Step4:
//Lets see if it works
div1.InnerText = c1.s1;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.