Custom Catalog Recomposition

Feb 13, 2010 at 6:36 PM

Hi Guys.

I wrote a Custom ComposablePartCatalog.

Now i want develop this catalog recomposable. I know that i have to implement the interface INotifyComposablePartCatalogChanged and use the AtomicComposition class.

My Question is how to use INotifyComposablePartCatalogChanged and AtomicComposition to make a Custom ComposablePartCatalog recomposable?



Feb 16, 2010 at 8:42 PM

It is unfortunate that once we added stable composition the change events in the catalogs and export providers became so complex. At any rate here is some sample code that will hopefully help you get the eventing correct.

IEnumerable<ComposablePartDefinition> addedDefinitions = ...   // Collect your proposed adds
IEnumerable<ComposablePartDefinition> removedDefinitions = ... // Collect your proposed removes

using (var atomicComposition = new AtomicComposition())
    // Before you actually store your changes into your internal state fire the changing event to ensure that 
    // the changes will not break the existing composition. Note that you may get calls to your Parts/GetExports and you 
    // must return the old values not the new ones the new ones will be considered by you passing them via the event args.
    var changingArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, removedDefinitions, atomicComposition);

    // Fire changing event... Keep in mind that this may very well throw a ChangeRejectedException

    // Store your changes to your internal state


// Fire the changed event... passing in null for the AtomicComposition argument, which signals that this event args is for
// a changed event as opposed to a changing event.
var changedArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, removedDefinitions, null);