MEF & Silverlight 4 Beta - Part 3, Catalogs
- Posted: Dec 31, 2009 at 2:27 AM
- 51,097 Views
- 5 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Part 3 of a series of screencasts looking at the new Managed Extensibility Framework (MEF) in the Silverlight 4 beta.
MEF is a framework that simplifies the design of extensible applications and components. It can flexibly and dynamically discover a set of loosely coupled components and analyse their dependencies in order to compose them together at run time.
In this screencast, we start to take a look at catalogs which provide one way in which MEF discovers the components that it can compose. We take a look at the catalogs built into the framework and what they do for us and also how MEF uses them to
populate a default CompositionContainer & how you can take control of that.
Tips for viewing:
I'm working to get together a Live Meeting in early 2010 with people from the MEF team in order that people can chat more about MEF in Silverlight. Stay tuned.
The next screencast in this series is
here.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Mike, this one was the eye opener for me. Not so much about MEF, but on a whole raft of technologies coming out of Microsoft.
MEF, Unity, and a few other things are ALL solutions built around this simple concept... type catalogs!
While they all sit on this base, they set out to achieve different things, and solve problems in their particular domain.
At first my biggest confusion was which product to use, since MEF and Unity solved an overlapping set of problems, but I didn't see the commonality, which is they use type catalogs to provide a mapping of types to be delivered anywhere in your application. Of course that's a simplified description of what they do, but at least I've resolved why they appear the same(at least in my warped mind).
Thanks!
Excellent video. The flow is nice and brisk, all the examples are set up well and I never found myself getting bored. Kudos for the additional visual materials like the notepad titling. It does a far better job of keeping the viewer's attention than staring at the desktop the whole time.
Really great job, Mike, thanks! I really enjoy how you dig into the framework so the average developer is educated and not blinded by the abstraction. I really enjoy watching all of your presentations and look forward to seeing more!
The code in this video is mostly working but the last part I can't get to work. There are some changes in the MEF libraries, so for example - PartInitializer is renamed to CompositionInitializer.
Here is the code I use, I could not comment out CompositionInitializer.SatisfyImports(this).
public partial class MainPage : UserControl
{
[Import]
public IWordProcessor WordProcessor { get; set; }
public MainPage()
{
InitializeComponent();
InitializeContainer();
CompositionInitializer.SatisfyImports(this);
}
private void InitializeContainer()
{
//TypeCatalog catalog = new TypeCatalog(
// typeof(WordProcessor), typeof(TextEngine));
//AssemblyCatalog catalog1 = new AssemblyCatalog(typeof(TextEngine).Assembly);
//AssemblyCatalog catalog2 = new AssemblyCatalog(typeof(WordProcessor).Assembly);
//AggregateCatalog catalog = new AggregateCatalog(catalog1, catalog2);
AggregateCatalog catalog = new AggregateCatalog();
foreach (var assemblyPart in Deployment.Current.Parts)
{
StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri(assemblyPart.Source, UriKind.Relative));
Assembly assembly = assemblyPart.Load(streamInfo.Stream);
catalog.Catalogs.Add(new AssemblyCatalog(assembly));
}
CompositionContainer container = new CompositionContainer(catalog);
CompositionHost.Initialize(container);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
int x = 2;
WordProcessor.ProcessUsingHighres();
}
}
//Is it possible to comment out the call to SatisfyImports?
Hi,
Sorry for replying so late to your question, I'd missed it as a comment.
In your code here, you're doing an import of a IWordProcessor onto your WordProcessor member variable. You're also (in the same class) initializing the composition container with all the Assemblies that have shipped with your Silverlight XAP.
By the way - you should *not* have to write that code because it is the default behaviour of MEF in Silverlight anyway so you should be able to get rid of all the code in the function InitializeContainer().
However, if you want MEF to satisfy the import that you have on your MainPage then you do need to call CompositionInitializer.SatisfyImports() on that instance so you can't comment that code out.
Hope that helps.
Mike.
Remove this comment
Remove this thread
close