Search code examples
c#silverlight-4.0mefautofaccomposite

MEF and Autofac in Silverlight 4 App


Just started working on a composite App that will multi-target WPF & Silverlight 4. It's quite likely that we'll allow some 3rd party plugins. Also, we'd like to partition the Silverlight app into multiple XAPs that can be independently downloaded/loaded.

We had thought that using MEF to control the Extension points (i.e. module composition) of the app and Autofac to handle dependencies within modules would be the way to go.

Here's the rub, though. Autofac doesn't appear to have SL4 MEF integration, so we can't simply register types from catalogs in the Silverlight code. Since we're using XAPs to partition the app, we need to use the MEF DeploymentCatalog to pull the new XAPs in as they download. We had considered simply registering types into Autofac (mostly views & viewmodels) by assembly, but there doesn't appear to be a way to get at the assemblies via the DeploymentCatalog. Are we missing something? Is there a way to get at the assemblies in the DeploymentCatalog after it downloads? Are we looking at this in the wrong way?

Feel free to ask for more detail if this isn't sufficient. Any help is always much appreciated.

Cheers,

Steve


Solution

  • If you're hitting friction here, I'd say your best bet is to embrace either MEF or Autofac 100%.

    The integration between the two works well for simple plug-in scenarios, but the MEF features that are appealing in Silverlight stem from MEF's "light up" capabilities, which Autofac does not support.

    Hope this helps,

    Nick