Basic cross process singleton

Feb 17, 2013 at 9:49 AM
I am trying to use MEF with VS2008 .NET 3.5 (Mef_Preview_9) to create a cross process singleton and everything I have tried returns a new instance.

I have created MetaDataModelServer and Client projects, both of which reference a separate IMetaDataModelServer project. When the Client is run multiple times I want them to return the same MetaDataModelServer instance but they always create a new one. My reading says that the default is [PartCreationPolicy(CreationPolicy.Shared)] but even explicitly specifying it, I still get a new instance.

I am feeling a bit stupid about this so please feel free to point out the obvious.
// IMetaDataModel.dll 
    public interface IMetaDataModelServer
        DateTime DateTimeCreated { get ;  }

    public interface IMetaDataModel
        DateTime DateTimeCreated { get; }

// MetaDataModel.dll references IMetaDataModel.dll 
    public class MetaDataModelServer : IMetaDataModel.IMetaDataModelServer {}
    public class MetaDataModel : IMetaDataModel.IMetaDataModel {}

// Client.dll references IMetaDataModel.dll
    class Client
        public IMetaDataModel.IMetaDataModelServer MetaDataModelServer;

        public Client()
            MessageBox.Show("ClientAddinConsole.MetaDataModelServer " + " " + MetaDataModelServer.DateTimeCreated.ToString() );

        private void Compose()
            dirCatalog = new DirectoryCatalog(@"D:\Projects\MEFExample\MetaDataModel\bin\Debug");
            CompositionContainer container = new CompositionContainer(dirCatalog);
Feb 25, 2013 at 8:59 PM
Hi there- MEF's "sharing" applies within a single instance of the composition container. There's no support for inter-process sharing, which I believe needs a different/morr resilient implementation approach than MEF aims to provide.