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 7928807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:51:18+00:00 2026-06-03T19:51:18+00:00

Background: I’m attempting to us MEF to import two assemblies implementing IFoo. To do

  • 0

Background: I’m attempting to us MEF to import two assemblies implementing IFoo. To do so, unsurprisingly, I’m using [ImportMany] to import all giving me an IEnumerable>. Then my consuming logic determines which of the imported assembly to use based on MetaData “Bar”.

Each exporter is decorated with an ExportMetadata attribute. This works fine when I have:

[Export(typeof(IFoo))]
[ExportMetadata("Bar", "Hello")]
public class Hello : IFoo
{...}

[Export(typeof(IFoo))]
[ExportMetadata("Bar", "World")]
public class World: IFoo
{...}

That is, my IEnumerable has two IFoos.

I want to define one as a default so if there is no need for “Hello” nor “World”, I’ll look for the one with “Default” as my Bar metadata. I have attempted to do this using IsMultiple property like this:

[Export(typeof(IFoo))]
[ExportMetadata("Bar", "Hello", IsMultiple = true)]
[ExportMetadata("Bar", "Default", IsMultiple = true)]
public class Hello : IFoo
{...}

Problem: When I add the IsMultiple property and second attribute, the Hello class is no longer pulled into the resulting IEnumerable.

Question: How do I tag a class for MEF with a second/default designation?

Thanks!

  • 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-03T19:51:20+00:00Added an answer on June 3, 2026 at 7:51 pm

    To expose multiple completely separate exports on a class like this, the best approach is to use multiple ‘property exports’ that in this case return ‘this’.

    class Hello: IFoo
    {
        [Export, ExportMetadata(...)]
        public IFoo Bar { get { return this; } }
    
        [Export, ExportMetadata(...)]
        public IFoo Default { get { return this; } }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I'm running a Minecraft server for friends on a VPS, and I'm attempting
Background: I'm investigating anonymous recursion, and I'm taking on the challenge of implementing the
Background I graduated 6 months ago, and my collaborative work in college has all
Background I have two select form fields chained together: duration and frequency. When the
Background: I am using Eclipse to develop an Android app. I have an xml
Background: At my company we are developing a bunch applications that are using the
Background I am writing and using a very simple CGI-based (Perl) content management tool
Background: Over the next month, I'll be giving three talks about or at least
Background: I am developing a web-based teaching program (using Drupal 7, if that matters)
Background Hi All, I'm trying to use Boost::MPI, at the moment I'm just trying

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.