Exemplo n.º 1
0
        public void PartTypeLoadedLazily()
        {
            var catalog   = new TypeLoadNotifyingCatalog(typeof(ExportingPart));
            var container = new CompositionContainer(catalog);

            catalog.AssertNotLoaded(typeof(ExportingPart));
            Assert.Equal(0, catalog.LoadedTypes.Count());

            Lazy <IExporter> lazyContract = container.GetExport <IExporter>();

            Assert.NotNull(lazyContract);
            catalog.AssertNotLoaded(typeof(ExportingPart));
            Assert.Equal(0, catalog.LoadedTypes.Count());

            IExporter value = lazyContract.Value;

            catalog.AssertLoaded(typeof(ExportingPart));
            Assert.Equal(1, catalog.LoadedTypes.Count());
        }
Exemplo n.º 2
0
        public void PartTypeLoadedLazilyEagerCollectionDependenciesLoadEagerly()
        {
            var catalog   = new TypeLoadNotifyingCatalog(typeof(ExportingPart), typeof(PartImportingCollectionEagerly));
            var container = new CompositionContainer(catalog);

            catalog.AssertNotLoaded(typeof(ExportingPart));
            catalog.AssertNotLoaded(typeof(PartImportingCollectionEagerly));
            Assert.Equal(0, catalog.LoadedTypes.Count());

            Lazy <IImporter> lazyContract = container.GetExport <IImporter>();

            Assert.NotNull(lazyContract);
            catalog.AssertNotLoaded(typeof(PartImportingCollectionEagerly));
            catalog.AssertNotLoaded(typeof(ExportingPart));
            Assert.Equal(0, catalog.LoadedTypes.Count());

            IImporter value = lazyContract.Value;

            catalog.AssertLoaded(typeof(PartImportingCollectionEagerly));
            catalog.AssertLoaded(typeof(ExportingPart));
            Assert.Equal(2, catalog.LoadedTypes.Count());
        }