Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top