View argument constructed once

33 views Asked by At

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?

1

There are 1 answers

0
Unril On BEST ANSWER

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