Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you hydrate a static property using MEF?

can I hydrate this inside the class's static constructor?

public class Connect:IDTExtensibility2, IDTCommandTarget
  static Connect()
    {
        //hydrate static properties?
    }
    [Import]
    public static Action<ProjectLogicChecks> Display { get; set; }

[Export(typeof(Action<ProjectLogicChecks>))]
    private static void DisplayResults( CheckProcesses _checkResults)
{
    MessageBox.Show(_checkResults.ProjectLogicCheck.AssemblyName + " has problems=" +
                    _checkResults.ProjectLogicCheck.HasProblems);
}
like image 956
Maslow Avatar asked Aug 16 '10 18:08

Maslow


2 Answers

No, MEF doesn't support static imports.

like image 132
Daniel Plaisted Avatar answered Oct 06 '22 03:10

Daniel Plaisted


You can use [ImportingConstructor] and set the static property in the constructor.

private static RandomService Random { get; set; }  
[ImportingConstructor] 
public ClientViewModel(RandomService random)
 {   
 Random = random; 
} 

Just don't set it to a static field.

like image 23
KCT Avatar answered Oct 06 '22 03:10

KCT