2

I need to instanciate many instances of the same View of a Prism module. I am using MEF: The Codeplex version has the ExportFactory attribute that allows multiple instance creation but Prism uses the .Net desktop version that has not this ExportFactory attribute. I tried to make Prism work with the CodePlex version but it seems this is not possible..

I found the Composition.Initialization.Desktop thing but I did not succeed in using it.

Any other ideas ?

2 Answers2

1

You can use the PartCreationPolicy attribute and set it to NonShared.

Or, you could also Export and Import a factory class that you then use to build the desired class.

Bryan Batchelder
  • 3,627
  • 21
  • 17
0

The next version of MEF for the desktop will have ExportFactory. You can download a preview from the MEF CodePlex site, which has support for ExportFactory on the desktop.

Daniel Plaisted
  • 16,674
  • 4
  • 44
  • 56
  • Yes, but the class needing this ExportFactory is a Prism Module and so must have a reference on the .Net MEF which has not the ExportFactory attribute ... – BernardSofaTeam May 11 '11 at 20:48
  • You could get the source code for Prism and compile it against the Codeplex version of MEF. Or you could look at MefContrib (http://mefcontrib.codeplex.com/), I think it may have something that enables ExportFactory or something similar in the .NET 4 version of MEF. – Daniel Plaisted May 12 '11 at 06:19
  • @okilele See my previous comment (which I forgot to mark as a reply to you) – Daniel Plaisted May 18 '11 at 03:08
  • Thanks Daniel, I recompiled Prism with the MEF Codeplex version and this works. – BernardSofaTeam Jun 06 '11 at 08:44