MEF: Do you know not to go overboard with dynamic dependencies?

Last updated by BrendanRichards over 7 years ago.See history

This rule has been archived
Archived Reason: Is anyone using MEF on their projects? Matt Wicks [RE: [SSW] Rules to Better Architecture and Code Review]

Using Managed Extensibility Framework to load dynamic dependencies at runtime can be useful, but it's not always required and does have some disadvantages. You shouldn't always look to MEF to implement a dynamic strategy.

If a reference doesn't need to be dynamically loaded at runtime, it's perfectly fine to have a default constructor that has a hardcoded instantiation of a dependency. If it was never a requirement to make that thing configurable or dynamic, don't invent business requirements just because using an IoC container is "fancier".

There are disadvantages to using dynamic loading of references:

  1. You lose your Code Analysis. Only static references can be analysed by code analysis tools.
  2. You lose your traceability. Visual Studio can no longer show you what concrete method is being called at design time.

More details on MEF can be foud here: http://msdn.microsoft.com/en-us/library/dd460648(v=vs.110).aspx

We open source. Powered by GitHub