MEF Faul ImportMany mit Creationpolicy.Nicht freigegeben

ich bin ein Anfänger in mef und so ich habe eine Frage 🙂
ich habe Folgendes:

[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);
        }

    }

den importierten Klassen alle markiert als nicht freigegeben.

[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
}

nun meine Frage: beim aufrufen von Open() ausführen, sollten es nicht immer eine neue NonShared1 Instanz erstellt werden? ich bekam immer die gleiche.

InformationsquelleAutor blindmeis | 2010-07-08
Schreibe einen Kommentar