CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Exporting configuration information in MEF through property exports

593 Views
Copy Code Show/Hide Line Numbers
// Below RecentlyUsedTrackerConfiguration provides configuration information through property exports. MEF pulls on the property getters and exports that info. 
// If the part needs to be data drvien, you can still access a service behind the scenes in the getter (or the constructor) to get the info.
 
public class RecentlyUsedTrackerConfiguration
{
  public RecentlyUsedTrackerConfiguration()
  {
     //set values here
  }
 
  [Export("RecentlyUsedTracker.File")]
  public string File {get;set;}
 
  [Export("RecentlyUsedTracker.MaxItems")]
  public int MaxItems {get;set;}
}
 
// The consumer is completely insulated and simply imports....such as below.
 
public class RecentlyUsedTracker {
  [Import("RecentlyUsedTracker.File")]
  public string File {get;set;}
 
  [Import("RecnetlyUsedTracker.MaxItems")]
  public int MaxItems {get;set;}
}
 
// RecentlyUsedTracker imports the config info above. Now for testing you just pass in the values you need in the test.
by Glenn Block
  January 26, 2010 @ 6:34pm
Tags:
Description:
Sample of exporting config and importing it.

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate