DefaultRuntimeComposer's GetCatalog

Jul 28, 2010 at 3:08 PM

Below code in class DefaultRuntimeComposer:

        private AggregateCatalog GetCatalog()
            var catalog = new AggregateCatalog();
            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var extensionPath = String.Format(@"{0}\Extensions\", baseDirectory);
1:            catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory));
2:           catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory, "*.exe"));            
            if (Directory.Exists(extensionPath))
                catalog.Catalogs.Add(new DirectoryCatalog(extensionPath));
            return catalog;



The 1 will lead all dlls in current dir be loaded,  even it has no exports or it is a win32 dll, wpf is slow when cold start or warm start, so better not load all dlls in start.

The 2 code will error if has win32 exe in current dir, e.g if I place a win32 splacescreen exe for WPF, the 2 code will error.

How about replaced with below code?

            catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory, "MEFedMVVM*.dll"));
            catalog.Catalogs.Add(new AssemblyCatalog(System.Reflection.Assembly.GetEntryAssembly()));




Jul 29, 2010 at 7:04 AM
No that would not work since you want all dlls to be parsed by MEF otherwise lets say you have a dll with ViewModels that are marked as Export, they would not be loaded into the MEF composition. Having said this if you want to improve perf on startup for your app you can create your own RuntimeComposer and feed it to MEFedMVVM via the LocatorBootstrapper.
Jul 29, 2010 at 10:45 AM

Thanks!  I see.