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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:17:08+00:00 2026-05-20T14:17:08+00:00

In Unity I would do something like this: Container.RegisterType<MyClass>(MyNamedInstance, new ContainerControlledLifetimeManager()); Then I could

  • 0

In Unity I would do something like this:

Container.RegisterType<MyClass>("MyNamedInstance", new ContainerControlledLifetimeManager());

Then I could put multiple instances of the same class in.

How can I do this in MEF?

  • 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-05-20T14:17:09+00:00Added an answer on May 20, 2026 at 2:17 pm

    It looks like named exports were added in the latest preview release (MEF 2 Preview 3) as part of MEF’s Convention Model (see the “explicit wiring” section).

    However, this is not yet available in .NET 4. Also, the APIs in the preview releases are subject to change.

    For now, you could create two exports for the same class with different contracts by adding the name to the export’s contract:

    public class MyClass
    {
    }
    
    public class MyClassExporter
    {
    
       [Export("Name1", typeof(MyClass))]
       public MyClass Name1
       {
           get
           {
               return new MyClass();
           }
       }
    
       [Export("Name2", typeof(MyClass))]
       public MyClass Name2
       {
           get
           {
               return new MyClass();
           }
       }
    }
    

    and then you could use the same contract for imports:

    [Export(typeof(IFoo))]
    public class Foo : IFoo
    {
       [ImportingConstructor]
       public Foo([Import("Name2", typeof(MyClass))] MyClass myClass)
       {
           ...
       }
    }
    

    Instead of using a MyClassExporter with property exports you could also put the export attributes on derived classes, which is perhaps easier to understand but doesn’t work on sealed classes:

    [Export("Name1", typeof(MyClass)]
    public class MyClass1 : MyClass
    {
    }
    
    [Export("Name2", typeof(MyClass)]
    public class MyClass2 : MyClass
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good morning, I would like to have an eager singleton in Unity, this singleton
I would like to know what a Unit test and Web Test is in
I would like to know what would be the best way to do unit
I would like to be able to add a message to a unit test,
My main JavaScript framework is jQuery , so I would like my unit test
I am pretty new to the Unity Application Block and am a little stuck
I'm using Prism and the Unity IoC container that comes along with Prism. However,
I am developing a Silverlight 3 application and I would like to delegate all
I have a repository pattern setup using NHibernate. The base class looks like this:
Please forgive the noob question. I've been developing this little app (with Unity) for

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.