title: How to release a shared instance from a MEF container
body: <p>I am trying to release a shared instance or singleton value. Does anyone know how to do this? Do I have to refresh the catalog? I'm learning MEF so please help.</p>
  
  <p>Example of class</p>
  
  <pre><code>[Export]
  public class Foo
  {
    public RandomProperty {get;set;}
  
    [ImportConstructor]
    public Foo() {}
  }
  </code></pre>
  
  <p>You can create it with something like this:</p>
  
  <pre><code>var fooSingleton = ServiceLocator.GetInstance(typeof(Foo));
  </code></pre>
  
  <p>All fine and good, but ideally I would like to do something like this</p>
  
  <pre><code>Container.Replace(oldFoo, newFoo);
  </code></pre>
  
  <p>So when I call it again</p>
  
  <pre><code>var fooSingleton = ServiceLocator.GetInstance(typeof(Foo));
  </code></pre>
  
  <p>fooSingleton will have the new value.</p>
  
  <p>I think the answer probably relies in actually clearing out the catalog and then refreshing it - but this seem overkill for such a simple thing.</p>