BT

Managed Extensibility Framework 2: Upcoming Changes for .NET 4.5

by Jenni Konrad on Apr 20, 2012 |

Version 2 of the Managed Extensibility Framework (MEF) is currently in Preview mode, and portions of it are now available in .NET Framework 4.5 Beta. According to Microsoft, the final supported release of MEF 2 will be included with .NET Framework 4.5, which is expected later this year.

In anticipation of its release, Dean Oliver detailed several of the updates in MEF 2. (As he mentions in his article, these items are subject to change before the final release.) A few of these updates include:

RegistrationBuilder: Attribute-less Registration
RegistrationBuilder is a new class in System.ComponentModel.Composition.Registration that handles part creation and export registration automatically, so that the developer no longer needs to define attributes on objects for injection. The RegistrationBuilder uses rules (called 'conventions') to map types to parts. For unique cases, it's also possible to override these conventions.

Flexible Type Registration
When using RegistrationBuilder, there are three ways to determine which types a rule will apply to:

  • ForType(): selects a single type
  • ForTypesDerivedFrom(): selects types that are assignable to either a base class or an interface (the same as InheritedExport in MEF 1)
  • ForTypesMatching(Predicate predicate): selects types that match a Boolean selector. This is the most flexible means of selection.

Multiple rules can be applied to a type, and will all be applied as long as none of the rules are in conflict.

Finer-Grained Control Over Lifetime
MEF 1 has two options for lifetime: per instance, or a shared global lifetime. ExportFactory improves granularity by allowing developers to create new instances of dependencies and control the lifetimes of the parts.

According to Oliver:

Instead of having the object generated when the parent object is generated you can gain access to the instance only when needed. ... This is sort of like a scoped import for a unit of work.

Microsoft is still soliciting feedback and feature suggestions for both MEF 2 and 3 on the MEF Discussion forum at CodePlex. For more information on recent changes in MEF 2, please visit the BCL Team Blog.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT