ObservableCollection does not get satisfied under deployment catalog

Apr 1, 2010 at 6:15 PM

for some reason when i'm using the deployment catalog the following propery doesn't get satisfied 

[ImportMany(AllowRecomposition = true)]
public ObservableCollection<string> PlugIns
{
 get;
 set;

while the following property does

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"));
 }
}

why does it happens?

Developer
Apr 1, 2010 at 11:20 PM

Out of curiosity how are you determining that it is not getting satisfied? If you are looking at the values in the setter then you are correct there will be no values in the ObservableCollection that is set but there will be in the IEumerable case (as well as the array case). The reason for this is for arrays and IEnumerable's we simply replace the entire value when it changes but for custom collections we only call clear followed by add for each item. We will only call the setter for a custom collection once, if and when we need to construct it for you. 

By the way this doesn't have anything to do with deployment catalog, it is MEF in general.

Apr 2, 2010 at 7:09 AM

That was my mistake.
At the construction level I was  doing
this.DataContext = this;
CompositionInitializer.SatisfyImports(this);

Instead of
CompositionInitializer.SatisfyImports(this);
this.DataContext = this;


So the binding was listen to null because
The ObservableCollection assignment occurs at the
SatisfyImport