Language: C#
Exporting configuration information in MEF through property exports
// 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.
Tags:
Description:
Sample of exporting config and importing it.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

