예제 #1
0
        public CompositionScopingService(ComposablePartCatalog allParts, Action <CompositionBatch> explicitExports, IEnumerable <string> possibleScopes)
        {
            //Contract.Requires( allParts != null );
            //Contract.Requires( explicitExports != null );
            //Contract.Requires( possibleScopes != null );
            //Contract.Requires( possibleScopes.Any() );

            var rootCatalog = allParts.OutOfScope(possibleScopes);

            _explicitExports = new ComposablePartExportProvider();
            _rootContainer   = new CompositionContainer(rootCatalog, CompositionOptions.DisableSilentRejection, _explicitExports);
            _explicitExports.SourceProvider = _rootContainer;

            var b = new CompositionBatch();

            explicitExports(b);
            b.AddExportedValue(RootScope);
            b.AddExportedValue(this as ICompositionScopingService);
            _explicitExports.Compose(b);

            _scopeCatalogs = possibleScopes.ToDictionary(s => s, s => allParts.Scope(s));
        }
 public static ComposablePartCatalog Scope(this ComposablePartCatalog catalog, params string[] scopeIds)
 {
     ////Contract.Requires( catalog != null );
     ////Contract.Requires( scopeIds != null );
     return(catalog.Scope((IEnumerable <string>)scopeIds));
 }