Updating Imports when an Exported property changes

Jan 12, 2010 at 4:48 AM

I'm wondering if the following is possible, and if so, what the strategy is to make it happen.

I have a property I'm exporting, like so:

 

    [Export]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class TEMP : NotifyPropertyChangedBase
    {
        private string myProperty = "My Value " + DateTime.Now;

        [Export("MyProperty")]
        public string MyProperty
        {
            get { return myProperty; }
            set
            {
                myProperty = value;
                OnPropertyChanged("MyProperty");
            }
        } 
    }

I then import "MyProperty" (obviously not using magic strings if I can help it)...and that's all good.

However, is there a way that if "MyProperty" changes I can force recomposition, and all "Imports" of "MyProperty" are subsequently updated?  

Just implementing INotifyPropertyChanged doesn't seem to do it.

[PS: I'm doing this in Silverlight...if that has any bearing on the approach]

Thanks!

 

Developer
Jan 12, 2010 at 6:23 PM

Unfortunately this approach will not work with MEF. Currently when a property is exported property value is only retrieved once and cached. If you want to be able to detect individual property changes you would need to export/import INotifyPropertyChanged or some other custom interface with an notification and listen for the change on the import side.

Jan 12, 2010 at 9:54 PM

Gotcha.  That makes sense.  Thanks.