Does CompositionInitializer.SatisfyImports(this) SL does not recompose

Mar 30, 2010 at 6:22 PM

i using the DeploymentCatalog with SL

but when i using  CompositionInitializer.SatisfyImports(this);

in the windows the following property does not recompose when the download complete

private IEnumerable<string> _plugIns;
[ImportMany(AllowRecomposition = true)]
public IEnumerable<string> PlugIns
{
 get {
  return _plugIns;
 }
 set {
  _plugIns = value;
  if(PropertyChanged != null)
   PropertyChanged(this,new PropertyChangedEventArgs("PlugIns"));
 }
}

if i'm using Composepart instead of CompositionInitializer.SatisfyImports(this);

it is working fine.

you can download the code for this issue at the following link

http://cid-9bf7c1a515d76a9a.skydrive.live.com/self.aspx/Code%20Samples/MEF/Catalogs/Deployment%20Catalog/SilverlightCatalogs.zip

 

Coordinator
Mar 30, 2010 at 11:41 PM

You are using CompositionInitializer.SatisfyImports in your MainPage class.  By default this method will satisfy imports with a container containing the parts in the main xap file.  To override this, you can call CompositionHost.Initialize (once, before any SatisfyImports calls) and either pass in a container to use or a list of catalogs.

You are creating the catalogs and containers correctly in App.xaml.cs, you just aren't calling CompositionHost.Initialize().  Instead of creating a container and calling Compose, I would put CompositionHost.Initialize(_catalogs) at the end of your InitializeContainer method.

I would also remove the AggregateCatalog export from your App class.  If you leave it there, and actually import it somewhere else, MEF will end up creating a new instance of the App class to supply the export, which can be quite confusing!  If you do need to export it, you can put a PartNotDiscoverableAttribute on your App class to keep it out of your catalog and then add it to the container with a call to ComposeParts.

Thanks,
Daniel 

Mar 31, 2010 at 5:42 AM

TNX