PartCreator<T>

Sep 11, 2009 at 11:27 AM

I see Microsoft.ComponentModel.Composition.DynamicInstantiation.dll  is included in the WPF download but the release notes say PartCreator<T> is Silverlight only.  Is there any reason why this wouldn't work with WPF?  It's exactly what I need!

Regards

Michael

Sep 11, 2009 at 2:59 PM

Hi Michael,

PartCreator won't be included in the .NET 4 version of MEF, so it is excluded from that version of the zip file.

You can however compile the Silverlight version of the code for .NET, or use a sample implementation of PartCreator for .NET included in the zip under /Samples/DynamicInstantiation, if either of those options works for you.

Regards,

Nick

Sep 11, 2009 at 3:29 PM

Thanks Nick,

I've got it working now.  I'd started by just replacing Lazy<T> with PartCreator<T> but got a CompositionException.

After much experimentation I tracked it down.  It seems this works:-

[ImportMany("PersonPart")]
  public ObservableCollection<PartCreator<IPart, ISelectableKind>> PersonParts
  {
   get { return _personParts; }
   set { _personParts = value; }
  }

but [ImportMany("PersonPart", typeof(IPart))] doesn't.  Bug?

Regards

Michael

Sep 11, 2009 at 9:38 PM

Thanks for following up, Michael. That is indeed strage - are you using the Silverlight binaries built for .NET, or the Microsoft.ComponentModel.Composition ones?

In either case this is probably a bug.

Regards,

Nick