public void CompositionServiceFromRootDoesNotSatisfySubScopeImports(IContainer container) { var root = container.GetExportedValue <RootPart>(); var objectWithSubScopedImports = new SubScopedPart(); Assert.Throws <CompositionFailedException>(() => root.CompositionService.SatisfyImportsOnce(objectWithSubScopedImports)); }
public void CompositionServiceFromSubScopeSatisfiesSubScopeImports(IContainer container) { var root = container.GetExportedValue <RootPart>(); var scope1Part = root.ScopeFactory.CreateExport().Value; var scope1Importer = new SubScopedPart(); scope1Part.CompositionService.SatisfyImportsOnce(scope1Importer); Assert.Same(scope1Part.AnotherSubScopedPart, scope1Importer.AnotherSubScopedPart); Assert.Same(root, scope1Importer.Root); // Also make sure that another scope gets distinct exports var scope2Part = root.ScopeFactory.CreateExport().Value; var scope2Importer = new SubScopedPart(); scope2Part.CompositionService.SatisfyImportsOnce(scope2Importer); Assert.Same(scope2Part.AnotherSubScopedPart, scope2Importer.AnotherSubScopedPart); Assert.NotSame(scope1Part.AnotherSubScopedPart, scope2Part.AnotherSubScopedPart); Assert.Same(root, scope2Importer.Root); }