How to decide which one should we choose to use MEF vs. any IoC?

In which scenario we should use what? and in what circumstances would we choose to use both together?


Tricky question - since the two do indeed overlap to a certain degree.

I would say this:

  • use any useful IoC if you're primarily concerned about dependency injection for the sake of decoupling your components, e.g. for the ability to be able to inject a mock instead (for testing)

  • use MEF especially if you're more into being extensible, e.g. be able to "load all assemblies from that directory that export a certain interface", and if you need to be extensible and open for third parties (like Visual Studio: offer a public API so others can write an extension for your app). This is where MEF really shines

For MEF and Unity, there's also the MEF and Unity Integration Layer to combine the strengths of both tools together.

I would also recommend you check out Ayende's excellent blog post on what differentiates MEF from an IoC.

Need Your Help

Angular Best practice: promise in a Factory or in a Controller?

javascript angularjs promise

I have a basic factory in my app that handles API calls. Currently I'm using the form:

Google Maps adding multiple markers using javascript

javascript google-maps marker

So this set of code is pulling in locations (Latitude, Longitude, and Address) from a C# backend. the backend code pulls data from a SQL database and inputs it into the ASP.Net DataField colum...