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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:37:59+00:00 2026-05-27T03:37:59+00:00

I’ve been comparing Unity and MEF (to be used in Prism) and was going

  • 0

I’ve been comparing Unity and MEF (to be used in Prism) and was going towards MEF. Alas, recently I saw Unity’s cool runtime dependency resolving – If I want to add a module, I should just add its view type using ServiceLocator and, if I have a dependency constructor stating the view model, Unity will initialize it for me, along with the VM’s dependencies (in other services and modules).

Is this kind of behavior supported in MEF?

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-05-27T03:38:00+00:00Added an answer on May 27, 2026 at 3:38 am

    Let’s ignore Unity and MEF for now, and look at what your describing.

    if I have a dependency constructor stating view model, Unity will initialize it for me, along with the VM’s dependencies (in other services and modules).

    This mechanism is called Dependency Injection (DI) and is an implementation of the Inversion of Control (IoC) principle. Also note, that DI is not the same as Service Location (SL).

    Your particular example is called constructor injection, whereby dependencies are injected into the type being constructed, therefore:

    public MyView(MyViewModel viewModel) { }
    

    Is a site for constructor injection. Now let’s look at the two different container technologies:

    Unity is an IoC container in the traditional sense. You register known parts at runtime, which builds a catalog, and when you request a part from the container, it will automatically resolve the required dependencies.

    MEF is built around discovery and composition of unknown parts, i.e., it builds it’s container by building a list from export providers (either catalogs, or other providers). When you request a part to be composed, it by default will select a parameter-less constructor, e.g.:

    public MyView() { }
    

    Unless you decorate the target constructor with an [ImportingConstructor] attribute, which allows MEF to select the appropriate constructor, and resolve any dependencies:

    [ImportingConstructor]
    public MyView(MyViewModel viewModel) { }
    

    Also note, that MEF supports property injection through [Import] and [ImportMany] attributes:

    [Import]
    public MyViewModel ViewModel { get; set; }
    

    Although, my preference is to use constructor injection, as it better describes the dependencies your class requires to operate.

    Now, at the time of writing, this is appropriate for MEF 1.0 using the Attributed Programming Model. With MEF 2.0, (and also via MEFContrib), there are mechanisms to support registration-based and convention-based programming models.

    So in short, yes you can use MEF for Dependency Injection.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.