I was reading somewhere that with MEF I can simply drop a dll into a directory and my application (with some MEF magic) will be able to read it and execute the code in it? Hopefully only classes that implement an interface that I define??
Can someone help me to get going, with some links maybe for my problem.
I've looked through some of the docs, but nothing seems to be what I'm after and its tricky when I don't know exactly what to search on...
Thx S
Here are two MEF "Getting Started" posts by Brad Abrams:
Note that these were written using preview versions of MEF, so there have been some changes. For example, AttributedAssemblyCatalog has been renamed to AssemblyCatalog, AggregatingComposablePartCatalog is now AggregatingCatalog, and the PackageCatalog on Silverlight is now DeploymentCatalog, and has had some other API changes.
Try reading Glenn Block's introduction to MEF in MSDN Magazine:
Managed Extensibility Framework: Building Composable Apps in .NET 4 with the Managed Extensibility Framework
You can support 'Recomposition' by marking the imports like:
[ImportMany(AllowRecomposition=true)]
public IMessageSender[] Senders { get; set; }
However, from what I can tell this doesn't automatically load the assemblies. The version of MEF that made it to .NET 4 (and I guess Preview 9 at complex) doesn't appear to load the assemblies automatically. I'm not sure if this behaviour changed as MEF was developed.
You'll need to add a FileSystemWatcher and call Refresh() on for example the DirectoryCatalog and listen for one or more these events:
catalog.Changed += new EventHandler<ComposablePartCatalogChangeEventArgs>(Catalog_Changed);
container.ExportsChanged += new EventHandler<ExportsChangeEventArgs>(Container_ExportsChanged);
directoryCat.Changed += new EventHandler<ComposablePartCatalogChangeEventArgs>(dCat_Changed);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With