If you haven’t seen Krys and David’s announcement, we just released another drop of MEF (I need to hold myself from breaking out in hysterics when I say that ) on CodePlex.
This release contains a whole grab bag of goodies, some of which may initially taste like sour candies (breaking changes), but are sweet in the middle. Most importantly, we’ve done a significant set of enhancements to the MEF codebase around Lifetime, Diagnostics, and Debugging.
New wiki pages
We’ve (well really Hammett) fleshed out all the TBD topics, plus added a ton of new ones both in our programming guide and the arch section.
Diagnostics and debugging
Since joining the team once thing that I’ve heard over and over is just how bad our debugging experience was. Not only did i hear it…I experience it first hand, some times live on stage :-) Well fortunately Nick and his feature crew (David and Jad/Zhen) spent the last several months focused on righting this wrong.
We’ve made significant improvements in the debugging experience to address some problematic scenarios and deliver a foundation for diagnostics in all MEF features and extensions.
The differences to note are:
Another difference will be the visualization of exceptions when they occur.
Previously you would see something like the following, which was difficult to navigate.
With the changes, you will now see.
Lifetime Management and Creation Policy
Another concern we heard from customers was around how MEF handles lifetime management for parts. In previous releases we allowed the exporter to declare that a part has either a singleton or factory (transient) lifetime.
Hammett and team (Wes, Daniel) have been working tirelessly to come up with a solution to this one. Hammett personally was no stranger to this problem form all the work he’s done on the castle stack. Upon joining the team this is one area that he was relentless about finding a solution to. I am thankful for his passion to see this through as there were several times we hit road blocks that seemed insurmountable.
In the new bits we have provided solutions to both of these problems.
Part.Any
Part.Shared
Part.NonShared
Import.Any
Shared
Non Shared
Import.Shared
No match
Import.NonShared
An importer specifies the required policy through the use of the new RequiredCreationPolicy as can be seen below.
[Export]
public class Window : System.Windows.Forms.Form
{
[Import(RequiredCreationPolicy = CreationPolicy.NonShared)]
public ExportCollection<IShape> Shapes { get; set; }
...
}
For example, below you can see where the jobExport is explicitly released from the container.
var container = new CompositionContainer(...);
var jobExports = container.GetExports<IJob>();
foreach(var jobExport in jobExports)
var jobProcessor = jobExport.GetExportedObject();
jobProcess.Process();
container.ReleaseExport(jobExport);
Be sure to check out the new wiki page on Lifetime for a much more detailed explanation.
This should be the last release where we introduce major API changes. We’re getting into the home stretch now, with Beta 1 around the corner. There’s still time for us to make fixes though so please get your feedback in.
Special thanks to Hammett for making sure this release got out the door and for the wiki page work. Also thanks to David and Daniel for their supporting efforts on the site. And thanks to the whole team for the awesome work they are doing! Lastly thank to you for your feedback!