9 March 2010 0 Comments

Neat Samples: Extend your F# program with MEF

Jomo Fisher—The Managed Extensibility Framework is an interesting new technology in .NET 4.0. It lets you set up a plug in system for your application so that your program can acquire new functionality just by, for example, adding a .dll into a particular directory

8 March 2010 0 Comments

Speaking on “Ignite your coding”

This Thursday, I’ll be joining John Bristowe and Joey Devilla to talk about composite applications, patterns, MEF and anything else that comes up. I am flexible :-) This is a live webcast where questions will be taken in real time, so ask away! I am selfish but no slides or demo prep sounds great to me! Register here: http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032439322&Culture=en-CA

28 August 2009 0 Comments

Analyze MEF Assemblies from the Command Line

In MEF Preview 6 we shipped a sample assembly called Microsoft.ComponentModel.Composition.Diagnostics , demonstrating the kinds of things that can be determined by (semi-) statically analyzing MEF catalogs.

31 July 2009 0 Comments

Silverlight 3 Navigation: Dynamically Loaded Pages… Now MEF Powered!

Recently David Poll posted a very cool technique for navigating to dynamically loaded pages and on demand downloading of pages in a Silverlight 3 application .  It was very cool but the explicit wire up of each page can be a pain in large applications.  So having just posted about MEF on Silverlight , I thought this was a great fit.  The Managed Extensibility Framework (MEF) is all about discovering and wiring up components and Silverlight 3 Navigation has some very interesting components.    But before I could get it done, our Test Manager, Dinesh Chandnani beat me to it.  He wrote this very cool example app that I extended just a bit. Download the all the source code and check out an live sample … The model is very simple.  You just create a page (via the Silverlight Page item template) and put metadata on them saying how to navigate to it.  The page can be in the same XAP or different XAP.  No need to wire them up.    For example, for a page in the same XAP, you just create a page and add some metadata to it 1: [PageMetadata(Content = "page1" , NavigateUri = "/page1" )] 2: public partial class Page1 : Page 3: { For a page in a different assembly, possibly delay loaded or conditionally loaded: 1: [PageMetadata(Content= "delayloaded" , 2: NavigateUri= "/DelayLoadedPages;component/DelayLoadedPage.dyn.xaml" )] 3: public partial class DelayLoadedPage : DynamicPage 4: { Pretty much the same, but we use the packURI syntax and David Poll’s Dynamic page classpattern (see his blog post above for more information)

11 April 2009 0 Comments

MEF Preview 5, changes and enhancements

We recently shipped MEF preview 5 on Codeplex , an exciting release. In the latest release, you’ll find we’ve made quite a few changes, and some really powerful enhancements to our previous codebase

7 April 2009 0 Comments

MEF in Office?

In my last post , I looked briefly at MEF, and I’m wondering how this model can be applied to Office add-ins. The Office add-in model itself already achieves a level of dynamic composition, by virtue of the fact that the set of add-ins to be loaded is only discovered at runtime

21 March 2009 0 Comments

Why doesn’t MEF support open-generics for exports? Because MEF is not type based.

I get this question all the time. Recently it popped it’s head on the forums in this thread (which I referred to in my last post ) In that thread, Andrew was asking why the following does not work? [Export( typeof (IDomainController<>)), CompositionOptions(CreationPolicy = CreationPolicy.Shared)] public class DomainController<T> : IDomainController<T> { /* some code here */ [ImportingConstructor] public DomainController(IRepository repository) {   _Repository = repository } } That is he wants to export a generic IDomainController with the idea the closed generic versions like IDomainController<Customer> could be imported

23 February 2009 0 Comments

Næste kig på Managed Extensibility Framework

Jeg kigger her på hvordan man bruger ImportingConstructor og loader assemblies dynamisk med MEF. Jeg bygger videre på eksemplet fra min første blogpost om MEF . Når man begynder at arbejde lidt videre med MEF, så kommer man hurtigt ud i, at man har mange imports og eksports.

9 February 2009 0 Comments

CommonServiceLocator for MEF, a service is a service.

Today, I finally got around to uploading a CommonServiceLocator adapter for MEF. The code is actually quite simple thanks to Chris Tavares providing ServiceLocatorImplBase public class MefServiceLocator : ServiceLocatorImplBase { private ExportProvider _provider; public MefServiceLocator(ExportProvider provider) { _provider = provider; } protected override object DoGetInstance(Type serviceType, string key) { IEnumerable<Export< object >> exports; string contract; if (key == null ) { contract = CompositionServices.GetContractName(serviceType); exports = _provider.GetExports< object >(contract); } else { exports = _provider.GetExports< object >(key); contract = key; } if (exports.Count() > 0) return exports.First().GetExportedObject(); else throw new ActivationException( string .Format( "Could not locate any instances of contract {0}" , key)); } protected override IEnumerable< object > DoGetAllInstances(Type serviceType) { var exports = _provider.GetExportedObjects< object >( CompositionServices.GetContractName(serviceType)); return exports; } } One thing you’ll notice is that in DoGetInstance, I am calling to GetExports and then manufacturing only the first export that I return