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.
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
[InheritedExport(typeof(IMetaDataModelServer))]
public interface IMetaDataModelServer
{
DateTime DateTimeCreated { get ; }
}
[InheritedExport(typeof(IMetaDataModel))]
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
{
[Import(typeof(IMetaDataModel.IMetaDataModelServer))]
public IMetaDataModel.IMetaDataModelServer MetaDataModelServer;
public Client()
{
Compose();
MessageBox.Show("ClientAddinConsole.MetaDataModelServer " + " " + MetaDataModelServer.DateTimeCreated.ToString() );
}
private void Compose()
{
dirCatalog = new DirectoryCatalog(@"D:\Projects\MEFExample\MetaDataModel\bin\Debug");
CompositionContainer container = new CompositionContainer(dirCatalog);
container.SatisfyImportsOnce(this);
//container.ComposeParts(this);
}
}