c# - How to retrieve/import object using MEF in Prism -
I need an object ( RuleFile
) for the whole application (* .docs) The file that will be attached to my application.
I am using Prism 5 with MEF as a dependency injection container. I now decorate the object with Please tell me what am I missing? Or tell me another way to handle this scenario better.
[Export] [Serializable (public)] Public Class Rule File: NotificationBase, IreneFile {}
[export]] < / Code> and trying to import it into one of
MyViewModel
but it is giving null
.
Public class MyViewModel: ViewModelBase {[Import] Private rulesfile rulefile; // 'tap' is coming here)
Are you checking the value in the constructor? Directly decorated on the property are resolved after the constructor. If you want to use the RuleFile
in the constructor, you must set this way
public class MyViewModel: ViewModelBase {public Niamfail RuleFile {get; Set; } [Importer resource] Public MyViewModel (RuleFile ruleFile) {RuleFile = ruleFile; }}
Alternatively, you can implement IPartImportsSatisfiedNotification
, which will give you an information method to inform that the import has been resolved . This way
public class MyViewModel: ViewModelBase, IPartImportsSetisfiedNotification {[Import] Public Rule File RuleFile {get; Set; } Public Zero OnImportsSatisfied () {// This indicates that the import has been solved}}
Comments
Post a Comment