MEF WPF application with separate builds and load controls

I have UI application extensions in separate DLL files that I connect with through MEF. My question is, if they have a dialog (a WPF user control), should I make the dialog an extension property as follows:

public UserControl ExtDialog { get; set; } 

or should i load them in uri package?

 public string ExtDialogUri { get; set; } 

I am leaning towards the uri package, but not sure if this will really work. How is this a more β€œrecommended” way to do this?

NOTE. These dialogs will be navigated using NavigationService.Navigate (); Method.

+4
source share
1 answer

I would not use any of the options. The fact is that both methods do not have flexibility with respect to the time it took to create a dialogue. If the first method is used, a dialog will always be created, regardless of whether it is needed or not. The problem with the package URL is that extensions will not control how dialog instances are created. What to do if the control needs to be initialized after creation (view model must be created, etc.)?

In my opinion, it is better to create a factory that will be used to create the dialog:

 public IExtDialogFactory ExtDialogFactory { get; set; } public interface IExtDialogFactory { UserControl CreateDialog(); } 
+4
source

Source: https://habr.com/ru/post/1335889/


All Articles