This project has moved and is read-only. For the latest updates, please go here.

Creation policy

Sep 19, 2011 at 10:00 AM

Hi all ,

I have a WPF application with many views , part of them is exported with creation policy "Shared" and part not "Shared"

the export of each view looks like this :

[ViewOfType(TypeName = "View1)]
public partial class PasswordConfirmationView : UserControl

I built a Navigation service with a method called NavigateTo(string viewName) in this method I get the view from the container and navigate to it . 
the navigation service has the following Views array which I query it for each view . 
public Lazy<UserControlIViewOfTypeCapabilities>[] Views;

my problem is with the views with creation policy "NonShared" , say I get an instance for a certain view , I did some work with it , then I called NavigationService.NavigateTo(viewName) 
then the service will create it a gain and here I have different instances of view .
How can do that if I use NavigateTo then to use the same instance that mef allready created it .

Thanks in advance ...

Sep 20, 2011 at 3:18 PM

I would suggest to create an interface IUserControlFactory, and Export an implementation called ViewFactory : IUserControlFactory


IUserControlFactory will have a method called CreateView(object someParam). 


That will give you a lot more control over how you create and return views to the containers.