Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8269935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:23:47+00:00 2026-06-08T06:23:47+00:00

Are there any configuration file settings for MEF, or is everything done in code?

  • 0

Are there any configuration file settings for MEF, or is everything done in code?

If everything is in code, what are some best practices for switching between different classes that do exports? i.e. if Class A and Class B both export IMyExport, what are some good ways to “configure” the app to use A or to use B?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:23:49+00:00Added an answer on June 8, 2026 at 6:23 am

    As far as I know, MEF doesn’t have a configuration file. In the case that you want your application to use one implementation over the other, you could possibly create a new ConfigurationCatalog which will get a configuration file as an input and will only export the parts it tells it to. It’s possible that something like that already exists in MefContrib, so I would check there.

    Other than that, it’s up to the classes themselves to decide which implementation they’d like to use. One possible way to achieve what you want is by using contract names

    [Export("My Contract Name", typeof(IMyExport))]
    public class A : IMyExport { }
    
    [Export("Another Contract Name", typeof(IMyExport))]
    public class B : IMyExport { }
    

    Then the class importing IMyExport can specify which of the parts it wants to use

    [Import("Another Contract Name")]
    public IMyExport MyExport { get; set; }
    

    If you know that a certain dependency IMyExport can be exported more than once, you can add metadata to the export and decide at runtime which of the exports you’d like to use according to its metadata. If you go with that direction, your code would look something like this

    [MySpecialExport(SomeData = "ABC")]
    public class A : IMyExport { }
    
    [MySpecialExport(SomeData = "DEF")]
    public class B : IMyExport { }
    
    public class MyClass
    {
        [ImportMany(typeof(IMyExport))]
        public IEnumerable<Lazy<IMyExport, IMyExportMetadata>> MyProperty { get; set; }
    
        public void DoSomething()
        {
            var myLazyExport = MyProperty.FirstOrDefault(x => x.Metadata.SomeData == "DEF");
            IMyExport myExport = myLazyExport.Value;
    
            // Do something with myExport
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any recommendations on how to keep an application level settings/configuration file in
Just wanted to check if there is any configuration or parameter to get statistics
I am wondering if there is any other configuration options for a default controller.
Is there any tools available to encrypt and decrypt Asp.net Web configuration sections like
Is there any open source web client php application without popup server configuration ,
In the Mercurial API, is there any way to read the configuration values associated
Is there any functional difference in Python between a try statement and an if
Is there any way to access the <compilation /> tag in a web.config file?
It's very common to have at least one configuration file in any project. Every
I see in the ruby-debug docs configuration settings for ruby-debug here: http://bashdb.sourceforge.net/ruby-debug.html#Debugger_002esettings But there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.