Within my class I have a class that imports a type like this:
[Import]
public ContactViewModel ContactViewModel { get; set; }
The type is defined like this:
[PartCreationPolicy(CreationPolicy.NonShared)]
[Export(typeof(ContactViewModel))]
public class ContactViewModel {}
I am expecting whenever I would read from the property, to get a new instance right?
Or maybe not…I keep getting the same instance, how do I force t to make me a new instance when using the property?
Many Thanks,
Are you sure you are recomposing your consumer class? The
NonSharedcreation policy will ensure that a new instance is created each time the part is required to compose, so I would check the other side of it, which is the class where you are[Import]-ing your part. Is that class being recomposed correctly?Your other option is to use an
ExportFactory, e.g.: