0

I have the following code as the constructor of a ViewModel class:

    [ImportingConstructor]
    public ItemDefViewModel(IItemDefView view)
        :base(view)
    {
        _Item = new ItemModel();
    }

This view model corresponds to a child window. When I run the child window once, close it and the try to run it again I get an exception telling me that I can't call Show, ShowDialog on a closed window. Does this mean that only 1 IItemDefView object is created? How should I go about this?

nakiya
  • 14,063
  • 21
  • 79
  • 118

1 Answers1

2

By default, MEF registring instances in container as singletones. To change this behavior, you need set property RequiredCreationPolicy in ImportAttribute to NonShared. See ImportAttribute.RequiredCreationPolicy Property, Parts Lifetime

Unril
  • 106
  • 1
  • 3