Exemplo n.º 1
0
        private MefHostServices CreateMefHostServices(IEnumerable <Assembly> assemblies)
        {
            ExportProvider exportProvider;

            if (assemblies is ImmutableArray <Assembly> array &&
                array == MefHostServices.DefaultAssemblies &&
                ExportProviderCache.LocalExportProviderForCleanup != null)
            {
                if (_hostServices != null)
                {
                    return(_hostServices);
                }

                exportProvider = ExportProviderCache.LocalExportProviderForCleanup;
            }
            else
            {
                exportProvider = ExportProviderCache.GetOrCreateExportProviderFactory(assemblies).CreateExportProvider();
            }

            Interlocked.CompareExchange(
                ref _hostServices,
                new ExportProviderMefHostServices(exportProvider),
                null);

            return(_hostServices);
        }
        private MefHostServices CreateMefHostServices(IEnumerable <Assembly> assemblies, bool requestingDefaultAssemblies)
        {
            if (requestingDefaultAssemblies && ExportProviderCache.ExportProviderForCleanup != null)
            {
                if (_hostServices == null)
                {
                    var hostServices = new ExportProviderMefHostServices(ExportProviderCache.ExportProviderForCleanup);
                    Interlocked.CompareExchange(ref _hostServices, hostServices, null);
                }

                return(_hostServices);
            }

            var catalog = ExportProviderCache.GetOrCreateAssemblyCatalog(assemblies);

            Interlocked.CompareExchange(
                ref _hostServices,
                new ExportProviderMefHostServices(ExportProviderCache.GetOrCreateExportProviderFactory(catalog).CreateExportProvider()),
                null);

            return(_hostServices);
        }