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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:50:43+00:00 2026-05-25T19:50:43+00:00

By default the ImportAttribute requires that exactly one part will satisfy the contract specified

  • 0

By default the ImportAttribute requires that exactly one part will satisfy the contract specified in the attribute. This behavior can be modified with the ImportAttribute.AllowDefault property. Essentially this changes the behavior to allow zero or one parts to satisfy the contract. If there are no parts, the default value for that import is used instead.

ImportManyAttribute allows zero or more parts to satisfy the contract. MEF will satisfy this import using an empty collection, or a singleton collection, or a set of parts depending on what it finds.

How do I tell MEF that the empty collection is invalid?

Should I:

  1. Implement IPartImportsSatisfiedNotification and throw an exception from OnImportsSatisfied if the collection is empty?
  2. Implement my own ImportOneOrMoreAttribute?
  3. Use some built in functionality of MEF that somehow I am missing?
  • 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-25T19:50:43+00:00Added an answer on May 25, 2026 at 7:50 pm

    MEF only understands three cardinalities by default: ZeroOrOne, ExactlyOne, or ZeroOrMore. See ImportCardinality. So you cannot express it yourself within the constraints of the MEF attributes. I would not suggest throwing exceptions in OnImportsSatisfied because you will likely run into other unpredictable issues.

    I’m afraid the best you can do is ImportMany and verify it in the context of when you would use these imports.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

by default PHP will not handle file uploads larger than 2MB, if one requires
default date format in DatePicker is yyyy-mm-dd but i need dd-mm-yyyy. This one solution
My default package name is com.xont.controller (R file contain that package.Eclipse generated one) .
The default 64 MB max heap memory can be small for a large Java
Default ASP.NET MVC project has one MapRoute like routes.MapRoute( Default, {controller}/, new { controller
The default controller in my ASP.NET MVC project is decorated with the [Authorize] attribute.
By default you cannot access a file that is uploaded until it has been
Why Default.aspx missing if I created ASP.NET MVC 2 project? And why this project
'Default UITableViewCell styles from Apple should not be used' Can somebody tell me what
By default Flask ends a session when the user closes the browser. How can

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.