I'm coming across some strange MEF behaviour in Prism, which I can't really explain. I've found a way around it that I'm not too happy with, so I'd really like to understand what's causing it.
I've declared my shell window class with a PartCreationPolicy
of NonShared
. And I'm trying to use the CompositionContainer.GetExportedValue<>()
function from my MefBootstrapper
to create a new instance of the Shell.
The strange thing is, if I call Container.GetExportedValue<>()
before the shell has been created, I get a new object of type Shell
, each time I call it. However, once the shell has been initialized, repeated calls to Container.GetExportedValue<>()
return the same instance of the Shell.
It's as if the shell initialization somehow re-registers my Shell export as a Shared.
However, I don't see any calls in the bootstrapper code that explicitly try to achieve this.
Can anyone explain:
- what action has this side effect
- How (if possible) to restore the
NonShared
behaviour, so I can create multiple shells using MEF/ServiceLocator.
Cheers,
Mark