Replace(Remove/Add) the shared object in MEF container

Aug 28, 2014 at 12:51 PM
Edited Aug 28, 2014 at 10:18 PM
This may be simple but as I am new to MEF arena that is why I am having some difficulty to figure out the solution to my problem.

I am working on an application using WPF and Prism with MEF as DI container. I want to tie my object (i.e. RuleFile) with each application instance by associating it with the file say RuleFile1.ruleapp. Therefore I have decorated it with attribute [PartCreationPolicy(CreationPolicy.Shared)] to treat it as singleton so that it remains same throughout the application with each application instance.
[Serializable()]
[Export]    
[PartCreationPolicy(CreationPolicy.Shared)]
public class RuleFile : NotifyPropertyChanged, IRuleFile { }
Next, at the time of ViewModel [ImportingContructor] as shown below, the object is same as desired.
[ImportingConstructor]
public RuleViewModel(RuleFile ruleFile)

[ImportingConstructor]
public SchemaViewModel(RuleFile ruleFile)
Until now everything is smooth.

Using below piece of code, i am trying to get the same exported object that is passing to view model as mentioned above but container.GetExportedValue<IRuleFile>() is giving a new object reference that is not the same one:
var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
var exportObj = container.GetExportedValue<IRuleFile>();
Question 1: Why i am getting a different reference although object should be the same as it is a singleton object with CreationPolicy.Shared?

Question 2: Ultimately this all effort is to exchange/replace RuleFile exported object with the deserialized one in the MEF DI container?