я новичок в MEF и поэтому у меня есть вопрос :) я следующее:MEF Ленивый ImportMany с Creationpolicy.NonShared
[PartCreationPolicy(CreationPolicy.Shared)]
[Export(typeof(SharedExport))]
public class SharedExport : INPCBase
{
[ImportMany(typeof(INonShared),RequiredCreationPolicy = CreationPolicy.NonShared)]
private IEnumerable<Lazy<INonShared,Dictionary<string,object>>> fac;
...
public void Open()
{
foreach (var lazy in fac)
{
this.Muster.Add(lazy.Value);
}
}
импортированные классы все помечены как NonShared.
[PartCreationPolicy(CreationPolicy.NonShared)]
[Export(typeof(INonShared))]
[ExportMetadata("Muster","030")]
public sealed class NonShared1 : INPCBase, INonShared
{
public NonShared1()
{
Debug.WriteLine("ctor NonShared1" + this.GetHashCode().ToString());
}
#region Implementation of INonShared
public string Displayname
{
get { return "Muster 030 "+ this.GetHashCode().ToString();
}
}
#endregion
}
сейчас мой вопрос: когда Open() выполнить, не должен ли всегда создаваться новый экземпляр NonShared1? я всегда был тем же.
thx для подсказки ExportFactory. Я дам ему попробовать :) – blindmeis