MVVM Light SimpleIoc instance resolution

969 views Asked by At

In my MVVM Light I display a dialog by having it implement an IModalWindow interface. I could register it using

SimpleIoc.Default.Register<IModalWindow, DialogView>();

Using this method though I cannot see how I can register different dialogs that implement the same interface and request the correct one. I looked at the factory method but could not find a suitable example.

Instead I used the following

SimpleIoc.Default.Register<IModalWindow>(() => { return new DialogView(); }, "DialogView");

which allows me to access a specific dialog type via the key, but since this is a singleton, I get an error when I attempt to show the dialog a second time because the instance has been closed.

This second method also allows a Mock to be used for unit testing by registering it with the same key.

How can I register different dialogs with SimpleIoc, get non-singleton instances and be able to unit test?

0

There are 0 answers