ContentLoader to pick content from MEF Plugin if not found in current assembly.

Feb 17, 2014 at 5:27 AM
I've read the MUI MEF Guide, but I'm wondering how I would construct a ContentLoader that would try to obtain the Content from the MEF Exported content (MEF plugin assembly), if and if not available, fallback to content from where the default content loader gets it from (current assembly).

Anyone have any ideas how to do this?
Feb 18, 2014 at 8:00 PM
..actually, this was very easy to accomplish. I'll post it here just in case it helps anyone:

I modified the MEFContentLoader to call its base implementation of LoadContent if a matching exported URI couldn't be found:
    [Export]
    public class MEFContentLoader : DefaultContentLoader
    {
        [ImportMany]
        private Lazy<IContent, IContentMetadata>[] Contents { get; set; }

        protected override object LoadContent(Uri uri)
        {
            // lookup the content based on the content uri in the content metadata
            var content = (from c in this.Contents
                           where c.Metadata.ContentUri == uri.OriginalString
                           select c.Value).FirstOrDefault();

            if (content == null)
            {
                return base.LoadContent(uri);
            }

            else
            {
                return content;
            }
        }
    }