MefBootstrapper loading referenced assemblies

Aug 18, 2010 at 5:13 PM

My main Silverlight project has references to other Silverlight libraries I have created. The sample MefBootstrapper only loads the parts that are within the main application assembly so all my exports in the other assemblies were not being added to the MEF container. For anyone who might need to do this I modified the Configure method so that the container will load all the exports from all referenced assemblies. This only works as written if you follow the convention of naming your libraries MyMainAppNameSpace.MyLibrary.


            string appNamespace = Application.Current.GetType().Namespace;

            var assemblies = Deployment.Current.Parts.Select(
                        ap => Application.GetResourceStream(new Uri(ap.Source, UriKind.Relative)))
                                stream => new AssemblyPart().Load(stream.Stream)).ToList();

            var projectAssemblies = from assembly in assemblies
                      where assembly.FullName.StartsWith(appNamespace)
                      select assembly;

            var composablePartCatalogs = 
                projectAssemblies.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>();