public void TestInitialize() { var exp = new CatalogExportProvider(Catalog = CreateCatalog()); var agg = new NancyExportProvider(exp); Container = new CompositionContainer(agg); exp.SourceProvider = agg; }
public CatalogExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition definition) { this._catalogExportProvider = catalogExportProvider; this._partDefinition = partDefinition; this._definition = definition; }
/// <summary> /// By default, we are configured to use MEF /// </summary> protected override void Configure() { // Add all assemblies to AssemblySource (using a temporary DirectoryCatalog). var directoryCatalog = new DirectoryCatalog(@"./"); AssemblySource.Instance.AddRange( directoryCatalog.Parts .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly) .Where(assembly => !AssemblySource.Instance.Contains(assembly))); // Prioritise the executable assembly. This allows the client project to override exports, including IShell. // The client project can override SelectAssemblies to choose which assemblies are prioritised. var priorityAssemblies = SelectAssemblies().ToList(); var priorityCatalog = new AggregateCatalog(priorityAssemblies.Select(x => new AssemblyCatalog(x))); var priorityProvider = new CatalogExportProvider(priorityCatalog); // Now get all other assemblies (excluding the priority assemblies). var mainCatalog = new AggregateCatalog( AssemblySource.Instance .Where(assembly => !priorityAssemblies.Contains(assembly)) .Select(x => new AssemblyCatalog(x))); var mainProvider = new CatalogExportProvider(mainCatalog); Container = new CompositionContainer(priorityProvider, mainProvider); priorityProvider.SourceProvider = Container; mainProvider.SourceProvider = Container; var batch = new CompositionBatch(); BindServices(batch); batch.AddExportedValue(mainCatalog); Container.Compose(batch); }
public PartCreatorExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition exportDefinition) { this._catalogExportProvider = catalogExportProvider; this._partDefinition = partDefinition; this._exportDefinition = exportDefinition; this._partCreatorExportDefinition = new PartCreatorExportDefinition(this._exportDefinition); }
public MEFedMVVMExportProvider(ComposablePartCatalog catalog) { _exportProvider = new CatalogExportProvider(catalog); //support recomposition _exportProvider.ExportsChanged += (s, e) => OnExportsChanged(e); _exportProvider.ExportsChanging += (s, e) => OnExportsChanging(e); }
public PartCreatorExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition exportDefinition) { this._catalogExportProvider = catalogExportProvider; this._partDefinition = partDefinition; this._exportDefinition = exportDefinition; this._partCreatorExportDefinition = new PartCreatorExportDefinition(this._exportDefinition); }
public CatalogExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition definition) { this._catalogExportProvider = catalogExportProvider; this._partDefinition = partDefinition; this._definition = definition; }
public void Compose() { AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); string executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string generatorsPath = Path.Combine(executionPath, "Generators"); CreatePathIfRequied(generatorsPath); generatorsCatalog = new DirectoryCatalog(generatorsPath); string uiPath = Path.Combine(executionPath, "UI"); CreatePathIfRequied(uiPath); UICatalog = new DirectoryCatalog(uiPath); AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(generatorsCatalog); catalog.Catalogs.Add(UICatalog); //Set the defaults.... CatalogExportProvider mainProvider = new CatalogExportProvider(assemblyCatalog); CompositionContainer container = new CompositionContainer(catalog, mainProvider); mainProvider.SourceProvider = container; var batch = new CompositionBatch(); batch.AddPart(this); RefreshCatalog refreshCatalog = new RefreshCatalog(generatorsCatalog, UICatalog); container.ComposeParts(refreshCatalog); container.Compose(batch); Logger.Write("Compose complete"); }
public static CompositionContainer RegisterCompositionService([NotNull] this Startup startup, [NotNull] IConfiguration configuration, [NotNull] string projectDirectory, [NotNull] Assembly callingAssembly, [NotNull, ItemNotNull] IEnumerable<string> additionalAssemblyFileNames, CompositionOptions options) { var toolsDirectory = configuration.GetString(Constants.Configuration.ToolsDirectory); if (options.HasFlag(CompositionOptions.AddWebsiteAssemblyResolver)) { // add an assembly resolver that points to the website/bin directory - this will load files like Sitecore.Kernel.dll AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => ResolveAssembly(args, configuration); } // add application assemblies var coreAssembly = typeof(Constants).Assembly; var catalogs = new List<ComposablePartCatalog> { new AssemblyCatalog(coreAssembly), new AssemblyCatalog(callingAssembly) }; var disableExtensions = configuration.GetBool("disable-extensions"); if (!disableExtensions && !options.HasFlag(CompositionOptions.DisableExtensions)) { // add additional assemblies - this is used in Sitecore.Pathfinder.Server to load assemblies from the /bin folder AddAdditionalAssemblies(catalogs, additionalAssemblyFileNames); // add assemblies from the tools directory AddFeatureAssemblies(catalogs, toolsDirectory); // add core extensions var coreExtensionsDirectory = Path.Combine(toolsDirectory, "files\\extensions"); var coreAssemblyFileName = Path.Combine(coreExtensionsDirectory, "Sitecore.Pathfinder.Core.Extensions.dll"); AddDynamicAssembly(catalogs, toolsDirectory, coreAssemblyFileName, coreExtensionsDirectory); AddAssembliesFromDirectory(catalogs, coreExtensionsDirectory); // add extension from [Project]/node_modules directory AddNodeModules(catalogs, coreAssemblyFileName, projectDirectory); // add projects extensions var projectExtensionsDirectory = configuration.GetString(Constants.Configuration.ProjectExtensionsDirectory); if (!string.IsNullOrEmpty(projectExtensionsDirectory)) { projectExtensionsDirectory = PathHelper.Combine(projectDirectory, projectExtensionsDirectory); var projectAssemblyFileName = Path.Combine(projectExtensionsDirectory, configuration.GetString(Constants.Configuration.ProjectExtensionsAssemblyFileName)); AddDynamicAssembly(catalogs, toolsDirectory, projectAssemblyFileName, projectExtensionsDirectory); AddAssembliesFromDirectory(catalogs, projectExtensionsDirectory); } } // build composition graph var exportProvider = new CatalogExportProvider(new AggregateCatalog(catalogs)); var compositionContainer = new CompositionContainer(exportProvider); exportProvider.SourceProvider = compositionContainer; // register the composition service itself for DI compositionContainer.ComposeExportedValue<ICompositionService>(compositionContainer); compositionContainer.ComposeExportedValue(configuration); return compositionContainer; }
public ScopeManager(CatalogExportProvider catalogExportProvider, CompositionScopeDefinition scopeDefinition) { ArgumentNullException.ThrowIfNull(catalogExportProvider); ArgumentNullException.ThrowIfNull(scopeDefinition); _scopeDefinition = scopeDefinition; _catalogExportProvider = catalogExportProvider; }
public ScopeManager(CatalogExportProvider catalogExportProvider, CompositionScopeDefinition scopeDefinition) { Assumes.NotNull(catalogExportProvider); Assumes.NotNull(scopeDefinition); this._scopeDefinition = scopeDefinition; this._catalogExportProvider = catalogExportProvider; }
public ScopeManager(CatalogExportProvider catalogExportProvider, CompositionScopeDefinition scopeDefinition) { Assumes.NotNull(catalogExportProvider); Assumes.NotNull(scopeDefinition); _scopeDefinition = scopeDefinition; _catalogExportProvider = catalogExportProvider; }
public AspectProvider(Func<ComposablePartCatalog> catalogResolver) { _exportProvider = new CatalogExportProvider(catalogResolver()); //support recomposition _exportProvider.ExportsChanged += (s, e) => OnExportsChanged(e); _exportProvider.ExportsChanging += (s, e) => OnExportsChanging(e); }
public InnerCatalogExportProvider(CatalogExportProvider outerExportProvider) { if (outerExportProvider == null) { throw new ArgumentNullException(nameof(outerExportProvider)); } _outerExportProvider = outerExportProvider; }
public void TestSetUp() { var typeCatalog = new TypeCatalog(typeof(CtorOrderProcessor), typeof(OrderProcessor)); var genericCatalog = new GenericCatalog(new TestGenericContractRegistry()); var aggregateCatalog = new AggregateCatalog(typeCatalog, genericCatalog); var provider = new CatalogExportProvider(aggregateCatalog); provider.SourceProvider = provider; ExportProvider = provider; }
private void LoadRegistriesFromCatalog() { using (var ep = new CatalogExportProvider(this.decoratedCatalog)) { ep.SourceProvider = ep; var registries = ep.GetExportedValues<IGenericContractRegistry>(); LoadTypeMappings(registries); } }
private void LoadTypeMappings(IDictionary<Type, Type> genericTypes) { using (var ep = new CatalogExportProvider(_decoratedCatalog)) { ep.SourceProvider = ep; var locators = ep.GetExportedValues<GenericContractTypeMapping>(); foreach (var locator in locators) genericTypes.Add(locator.GenericContractTypeDefinition, locator.GenericImplementationTypeDefinition); } }
public void TestSetUp() { var typeCatalog = new TypeCatalog(typeof(CtorOrderProcessor), typeof(OrderProcessor), typeof(TestGenericContractRegistry)); var cfg = new InterceptionConfiguration().AddHandler(new GenericExportHandler()); var catalog = new InterceptingCatalog(typeCatalog, cfg); var provider = new CatalogExportProvider(catalog); provider.SourceProvider = provider; ExportProvider = provider; }
public void Constructor_ValueAsCatalogArgument_ShouldSetCatalogPropertyToEmpty() { var expectations = Expectations.GetCatalogs(); foreach (var e in expectations) { var provider = new CatalogExportProvider(e); Assert.AreSame(e, provider.Catalog); } }
static NuPatternGlobalContainer() { var globalComponentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel)); if (globalComponentModel == null) { tracer.Warn(Resources.NuPatternGlobalContainer_TraceNoComponentModelService); } else { var catalog = globalComponentModel.GetCatalog(NuPattern.ComponentModel.Composition.Catalog.DefaultCatalogName); if (catalog == null) { tracer.Warn(Resources.NuPatternGlobalContainer_TraceNoComponentModel, NuPattern.ComponentModel.Composition.Catalog.DefaultCatalogName); } else { try { // // Create our DecoratingReflectionCatalog // var componentsCatalog = new ComponentCatalog(catalog); // // Now create a catalog provider // CatalogExportProvider catalogProvider = new CatalogExportProvider(componentsCatalog); // // have it inherit the global provider // catalogProvider.SourceProvider = globalComponentModel.DefaultExportProvider; // // Create provider settings to look here first and then include others when not found // var providerSettings = new VsExportProviderSettings( VsExportProvidingPreference.BeforeExportsFromOtherContainers, VsExportSharingPolicy.IncludeExportsFromOthers); //Instance = VsCompositionContainer.Create(componentsCatalog, providerSettings); Instance = new CompositionContainer(componentsCatalog, globalComponentModel.DefaultExportProvider); } catch (Exception ex) { tracer.Error(ex, Resources.NuPatternGlobalContainer_TraceFailedContainerInitialization); throw; } } } }
/// <summary> /// Initializes a new instance of the <see cref="CompositionContainer"/> class /// with the specified catalog and export providers. /// </summary> /// <param name="compositionSettings"> /// <see cref="CompositionOptions"/> enumeration with flags controlling the composition. /// </param> /// <param name="providers"> /// A <see cref="Array"/> of <see cref="ExportProvider"/> objects which provide /// the <see cref="CompositionContainer"/> access to <see cref="Export"/> objects, /// or <see langword="null"/> to set <see cref="Providers"/> to an empty /// <see cref="ReadOnlyCollection{T}"/>. /// </param> /// <exception cref="ArgumentException"> /// <paramref name="providers"/> contains an element that is <see langword="null"/>. /// </exception> public CompositionContainer(ComposablePartCatalog catalog, CompositionOptions compositionOptions, params ExportProvider[] providers) { if (compositionOptions > (CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe | CompositionOptions.ExportCompositionService)) { throw new ArgumentOutOfRangeException("compositionOptions"); } this._compositionOptions = compositionOptions; this._partExportProvider = new ComposablePartExportProvider(compositionOptions); this._partExportProvider.SourceProvider = this; bool multiProvider = (catalog != null) || providers.Length > 0; if (multiProvider) { if (catalog != null) { this._catalogExportProvider = new CatalogExportProvider(catalog, compositionOptions); this._catalogExportProvider.SourceProvider = this; this._localExportProvider = new AggregateExportProvider(this._partExportProvider, this._catalogExportProvider); } else { this._localExportProvider = new AggregateExportProvider(this._partExportProvider); } if (providers != null && providers.Length > 0) { this._ancestorExportProvider = new AggregateExportProvider(providers); this._rootProvider = new AggregateExportProvider(this._localExportProvider, this._ancestorExportProvider); } else { this._rootProvider = this._localExportProvider; } } else { this._rootProvider = this._partExportProvider; } //Insert Composition Service if (compositionOptions.HasFlag(CompositionOptions.ExportCompositionService)) { this.ComposeExportedValue <ICompositionService>(new CompositionServiceShim(this)); } this._rootProvider.ExportsChanged += this.OnExportsChangedInternal; this._rootProvider.ExportsChanging += this.OnExportsChangingInternal; this._providers = (providers != null) ? new ReadOnlyCollection <ExportProvider>((ExportProvider[])providers.Clone()) : EmptyProviders; }
public ScopeManager(CatalogExportProvider catalogExportProvider, CompositionScopeDefinition scopeDefinition) { if (catalogExportProvider == null) { throw new ArgumentNullException(nameof(catalogExportProvider)); } if (scopeDefinition == null) { throw new ArgumentNullException(nameof(scopeDefinition)); } _scopeDefinition = scopeDefinition; _catalogExportProvider = catalogExportProvider; }
public static CatalogExport CreateExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition definition, CreationPolicy importCreationPolicy) { CreationPolicy partPolicy = partDefinition.Metadata.GetValue <CreationPolicy>(CompositionConstants.PartCreationPolicyMetadataName); bool isSharedPart = ShouldUseSharedPart(partPolicy, importCreationPolicy); if (isSharedPart) { return(new CatalogExport(catalogExportProvider, partDefinition, definition)); } else { return(new NonSharedCatalogExport(catalogExportProvider, partDefinition, definition)); } }
public static CatalogExport CreateExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition definition, CreationPolicy importCreationPolicy) { CreationPolicy partPolicy = partDefinition.Metadata.GetValue<CreationPolicy>(CompositionConstants.PartCreationPolicyMetadataName); bool isSharedPart = ShouldUseSharedPart(partPolicy, importCreationPolicy); if (isSharedPart) { return new CatalogExport(catalogExportProvider, partDefinition, definition); } else { return new NonSharedCatalogExport(catalogExportProvider, partDefinition, definition); } }
public CompositionContainer(ComposablePartCatalog catalog, bool isThreadSafe, params ExportProvider[] providers) { this._isThreadSafe = isThreadSafe; this._partExportProvider = new ComposablePartExportProvider(isThreadSafe); this._partExportProvider.SourceProvider = this; // the count of all aggregrated providers = 1 (Part EP) + 1 (Catalog EP, if present) + count of given providers; int reservedProvidersLength = 1 + ((catalog != null) ? 1 : 0); int aggregatedProvidersLength = reservedProvidersLength + ((providers != null) ? providers.Length : 0); if (aggregatedProvidersLength > 1) { ExportProvider[] aggregatedProviders = new ExportProvider[aggregatedProvidersLength]; // Add the parts provider aggregatedProviders[0] = this._partExportProvider; // Add the catalog provider if (catalog != null) { this._catalogExportProvider = new CatalogExportProvider(catalog, isThreadSafe); this._catalogExportProvider.SourceProvider = this; aggregatedProviders[1] = this._catalogExportProvider; } // Add the rest of providers if ((providers != null) && (providers.Length > 0)) { Array.Copy(providers, 0, aggregatedProviders, reservedProvidersLength, providers.Length); } // Create the aggregating provider and if any of the aggregatedProviders is null the constructor will throw an ArgumentExeption this._aggregatingExportProvider = new AggregateExportProvider(aggregatedProviders); this._rootProvider = this._aggregatingExportProvider; } else { Assumes.IsTrue(aggregatedProvidersLength == 1); this._rootProvider = this._partExportProvider; } this._rootProvider.ExportsChanged += this.OnExportsChangedInternal; this._rootProvider.ExportsChanging += this.OnExportsChangingInternal; this._providers = (providers != null) ? new ReadOnlyCollection <ExportProvider>((ExportProvider[])providers.Clone()) : EmptyProviders; }
public CompositionContainer(ComposablePartCatalog catalog, bool isThreadSafe, params ExportProvider[] providers) { this._importEngine = new ImportEngine(this, isThreadSafe); this._partExportProvider = new ComposablePartExportProvider(isThreadSafe); this._partExportProvider.SourceProvider = this; this._providers = new ReadOnlyCollection <ExportProvider>(providers != null ? (ExportProvider[])providers.Clone() : new ExportProvider[0]); List <ExportProvider> providerList = new List <ExportProvider>(); providerList.Add(this._partExportProvider); if (catalog != null) { this._catalogExportProvider = new CatalogExportProvider(catalog, isThreadSafe); this._catalogExportProvider.SourceProvider = this; providerList.Add(this._catalogExportProvider); } foreach (var provider in this._providers) { if (provider == null) { throw ExceptionBuilder.CreateContainsNullElement("providers"); } providerList.Add(provider); } // we only build the aggregating provider if necessary - that is, if we have more than one provider to aggregate if (providerList.Count > 1) { this._aggregatingExportProvider = new AggregateExportProvider(providerList); this._rootProvider = this._aggregatingExportProvider; } else { Assumes.IsTrue(providerList.Count == 1); this._rootProvider = providerList[0]; } this._rootProvider.ExportsChanged += this.OnExportsChangedInternal; this._rootProvider.ExportsChanging += this.OnExportsChangingInternal; }
public EmbeddedMessageContentHandlerRepository() { var libChorusAssembly = Assembly.GetExecutingAssembly(); //Set the codebase variable appropriately depending on the OS var codeBase = libChorusAssembly.CodeBase.Substring(LinuxUtils.IsUnix ? 7 : 8); var baseDir = Path.GetDirectoryName(codeBase); // REVIEW: for some reason using *.* or *.dll didn't work - creating the catalogs in // unit tests (on Linux) failed with FileNotFoundException - don't know why. using (var aggregateCatalog = new AggregateCatalog(new DirectoryCatalog(baseDir, "Chorus.exe"), new AssemblyCatalog(libChorusAssembly))) using (var catalog = new FilteredCatalog(aggregateCatalog, def => !def.Metadata.ContainsKey("IsDefault"))) using (var defaultExportProvider = new CatalogExportProvider(new TypeCatalog(typeof(IEmbeddedMessageContentHandler)))) { using (var container = new CompositionContainer(catalog, defaultExportProvider)) { defaultExportProvider.SourceProvider = container; container.ComposeParts(this); } } }
public ControllerServiceResolver() { // Create MEF catalog based on existing exports and convention model var registration = new RegistrationBuilder(); registration.ForTypesDerivedFrom<Controller>().SetCreationPolicy(CreationPolicy.NonShared).Export(); //registration.ForTypesMatching(t => t.FullName.StartsWith(Assembly.GetExecutingAssembly().GetName().Name + ".Parts.")) // .SetCreationPolicy(CreationPolicy.NonShared) // .ExportInterfaces(x => x.IsPublic); //var filteredCatalog = new FilteringCatalog(defaultCatalog, // def => !def.Metadata.ContainsKey("ServiceType") || string.Equals((string)def.Metadata["ServiceType"], "...", StringComparison.OrdinalIgnoreCase)); var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly(), registration); var defaults = new CatalogExportProvider(new TypeCatalog(DefaultGalleryServiceType)); Container = new CompositionContainer(catalog, defaults); defaults.SourceProvider = Container; Container.ComposeParts(this); }
public PartCreatorExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition exportDefinition) : base(partDefinition, exportDefinition) { _catalogExportProvider = catalogExportProvider; }
public void RemovingAndReAddingMultipleDefinitionsFromCatalog() { var fixedParts = new TypeCatalog(typeof(RootMultipleImporter), typeof(ExportedService)); var changingParts = new TypeCatalog(typeof(Exporter1), typeof(Exporter2)); var catalog = new AggregateCatalog(); catalog.Catalogs.Add(fixedParts); catalog.Catalogs.Add(changingParts); var catalogExportProvider = new CatalogExportProvider(catalog); catalogExportProvider.SourceProvider = catalogExportProvider; var root = catalogExportProvider.GetExport<RootMultipleImporter>().Value; Assert.AreEqual(2, root.Imports.Length); catalog.Catalogs.Remove(changingParts); Assert.AreEqual(0, root.Imports.Length); catalog.Catalogs.Add(changingParts); Assert.AreEqual(2, root.Imports.Length); }
public void CanBeCollectedAfterDispose() { AggregateExportProvider sourceExportProvider = new AggregateExportProvider(); var catalog = new AggregateCatalog(CatalogFactory.CreateDefaultAttributed()); var catalogExportProvider = new CatalogExportProvider(catalog); catalogExportProvider.SourceProvider = sourceExportProvider; WeakReference weakCatalogExportProvider = new WeakReference(catalogExportProvider); catalogExportProvider.Dispose(); catalogExportProvider = null; GC.Collect(); GC.WaitForPendingFinalizers(); Assert.IsFalse(weakCatalogExportProvider.IsAlive); GC.KeepAlive(sourceExportProvider); GC.KeepAlive(catalog); }
public void Recomposition_PartDefWithNonRecomposableImportIsRemoved_ExportsMatchingImportChanged_ShouldNotBeRejected() { string dependencyContractName = "dependency"; var exportValue = new object(); var exporterPart = PartFactory.CreateExporter(dependencyContractName, exportValue); var importerPart = PartFactory.CreateImporter(dependencyContractName, false); var exporterCatalog = CatalogFactory.Create(exporterPart); var importerCatalog = CatalogFactory.Create(importerPart); var aggregateCatalog = CatalogFactory.CreateAggregateCatalog(importerCatalog, exporterCatalog); var provider = new CatalogExportProvider(aggregateCatalog); provider.SourceProvider = provider; var exports = provider.GetExports(importerPart.ImportDefinitions.Single()); Assert.AreEqual(exportValue, importerPart.Value, "Importer was not composed"); aggregateCatalog.Catalogs.Remove(importerCatalog); aggregateCatalog.Catalogs.Remove(exporterCatalog); Assert.AreEqual(exportValue, importerPart.Value, "Importer was unexpectedly recomposed"); }
public void GetExports_NoSourceProvider_ShouldThrowInvalidOperation() { var catalog = CatalogFactory.CreateAttributed(); var provider = new CatalogExportProvider(catalog); ExceptionAssert.Throws<InvalidOperationException>(() => provider.GetExports(ImportFromContract("Foo"))); }
public void CreationPolicyNonShared_MultipleCallsReturnsDifferentInstances() { var catalog = CatalogFactory.CreateAttributed(typeof(CreationPolicyNonShared)); var provider = new CatalogExportProvider(catalog); provider.SourceProvider = ContainerFactory.Create(); List<CreationPolicyNonShared> list = new List<CreationPolicyNonShared>(); var export = provider.GetExportedValue<CreationPolicyNonShared>(); list.Add(export); for (int i = 0; i < 5; i++) // 5 is arbitrarily chosen { export = provider.GetExportedValue<CreationPolicyNonShared>(); CollectionAssert.DoesNotContain(list, export); list.Add(export); } }
public void CreationPolicyShared_MultipleCallsReturnSameInstance() { var catalog = CatalogFactory.CreateAttributed(typeof(CreationPolicyShared)); var provider = new CatalogExportProvider(catalog); provider.SourceProvider = ContainerFactory.Create(); var export = provider.GetExportedValue<CreationPolicyShared>(); for (int i = 0; i < 5; i++) // 5 is arbitrarily chosen { var export1 = provider.GetExportedValue<CreationPolicyShared>(); Assert.AreEqual(export, export1); } }
public NonSharedCatalogExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition definition) : base(catalogExportProvider, partDefinition, definition) { }
public void BasicTestWithRequiredMetadata_WrongTypeConstraint() { var catalog = CatalogFactory.CreateDefaultAttributed(); var catalogExportProvider = new CatalogExportProvider(catalog); catalogExportProvider.SourceProvider = catalogExportProvider; Assert.AreEqual(0, catalogExportProvider.GetExports(ImportFromContractAndMetadata("MyExporterWithNoFoo", new string[] { "Foo" }, new Type[] { typeof(int) })).Count()); Assert.AreEqual(0, catalogExportProvider.GetExports(ImportFromContractAndMetadata("MyExporterWithFoo", new string[] { "Foo" }, new Type[] { typeof(int) })).Count()); Assert.AreEqual(0, catalogExportProvider.GetExports(ImportFromContractAndMetadata("MyExporterWithFoo", new string[] { "Foo", "Bar" }, new Type[] { typeof(int), typeof(int) })).Count()); Assert.AreEqual(0, catalogExportProvider.GetExports(ImportFromContractAndMetadata("MyExporterWithNoFoo", new string[] { "Foo" }, new Type[] { typeof(int) })).Count()); Assert.AreEqual(0, catalogExportProvider.GetExports(ImportFromContractAndMetadata("MyExporterWithFoo", new string[] { "Foo" }, new Type[] { typeof(int) })).Count()); }
public void BasicTest() { var catalog = CatalogFactory.CreateDefaultAttributed(); var catalogExportProvider = new CatalogExportProvider(catalog); catalogExportProvider.SourceProvider = catalogExportProvider; var testName = AttributedModelServices.GetContractName(typeof(CatalogComponentTest)); var testNameNonComponent = AttributedModelServices.GetContractName(typeof(CatalogComponentTestNonComponentPart)); var testInterfaceName = AttributedModelServices.GetContractName(typeof(ICatalogComponentTest)); Assert.AreEqual(1, catalogExportProvider.GetExports(ImportFromContract(testName)).Count()); Assert.AreEqual(0, catalogExportProvider.GetExports(ImportFromContract(testNameNonComponent)).Count()); var exports = catalogExportProvider.GetExports(ImportFromContract(testInterfaceName)); Assert.AreEqual(2, exports.Count(), "There should be 2 of them"); foreach (var i in exports) Assert.IsNotNull(i.Value, "Should get a value"); }
public InnerCatalogExportProvider(CatalogExportProvider outerExportProvider) { ArgumentNullException.ThrowIfNull(outerExportProvider); _outerExportProvider = outerExportProvider; }
public ScopeManager(CatalogExportProvider catalogExportProvider !!, CompositionScopeDefinition scopeDefinition !!)
public PartCreatorExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition exportDefinition) : base(partDefinition, exportDefinition) { this._catalogExportProvider = catalogExportProvider; }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (!_isDisposed) { ExportProvider rootProvider = null; IDisposable disposableAncestorExportProvider = null; IDisposable disposableLocalExportProvider = null; IDisposable disposableRootProvider = null; ComposablePartExportProvider partExportProvider = null; CatalogExportProvider catalogExportProvider = null; ImportEngine importEngine = null; lock (_lock) { if (!_isDisposed) { rootProvider = _rootProvider; _rootProvider = null; disposableRootProvider = _disposableRootProvider; _disposableRootProvider = null; disposableLocalExportProvider = _disposableLocalExportProvider; _disposableLocalExportProvider = null; _localExportProvider = null; disposableAncestorExportProvider = _disposableAncestorExportProvider; _disposableAncestorExportProvider = null; _ancestorExportProvider = null; partExportProvider = _partExportProvider; _partExportProvider = null; catalogExportProvider = _catalogExportProvider; _catalogExportProvider = null; importEngine = _importEngine; _importEngine = null; _isDisposed = true; } } if (rootProvider != null) { rootProvider.ExportsChanged -= OnExportsChangedInternal; rootProvider.ExportsChanging -= OnExportsChangingInternal; } if (disposableRootProvider != null) { disposableRootProvider.Dispose(); } if (disposableAncestorExportProvider != null) { disposableAncestorExportProvider.Dispose(); } if (disposableLocalExportProvider != null) { disposableLocalExportProvider.Dispose(); } if (catalogExportProvider != null) { catalogExportProvider.Dispose(); } if (partExportProvider != null) { partExportProvider.Dispose(); } if (importEngine != null) { importEngine.Dispose(); } } } }
public InnerCatalogExportProvider(CatalogExportProvider outerExportProvider !!) {
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (!this._isDisposed) { ExportProvider rootProvider = null; AggregateExportProvider aggregatingExportProvider = null; ComposablePartExportProvider partExportProvider = null; CatalogExportProvider catalogExportProvider = null; ImportEngine importEngine = null; lock (this._lock) { if (!this._isDisposed) { rootProvider = this._rootProvider; this._rootProvider = null; aggregatingExportProvider = this._aggregatingExportProvider; this._aggregatingExportProvider = null; partExportProvider = this._partExportProvider; this._partExportProvider = null; catalogExportProvider = this._catalogExportProvider; this._catalogExportProvider = null; importEngine = this._importEngine; this._importEngine = null; this._isDisposed = true; } } if (rootProvider != null) { rootProvider.ExportsChanged -= this.OnExportsChangedInternal; rootProvider.ExportsChanging -= this.OnExportsChangingInternal; } if (aggregatingExportProvider != null) { aggregatingExportProvider.Dispose(); } if (catalogExportProvider != null) { catalogExportProvider.Dispose(); } if (partExportProvider != null) { partExportProvider.Dispose(); } if (importEngine != null) { importEngine.Dispose(); } } } }
public void ComponentCatalogResolverComponentCatalogExportReference() { var catalog = CatalogFactory.CreateDefaultAttributed(); var catalogExportProvider = new CatalogExportProvider(catalog); catalogExportProvider.SourceProvider = catalogExportProvider; var exports = catalogExportProvider.GetExports(ImportFromContract(AttributedModelServices.GetContractName(typeof(MyExporterWithValidMetadata)))); Assert.AreEqual(1, exports.Count()); var export = exports.First(); Assert.AreEqual("world", export.Metadata["hello"]); Assert.IsInstanceOfType(export.Value, typeof(MyExporterWithValidMetadata)); }
/// <summary> /// Initializes a new instance of the <see cref="CompositionContainer"/> class /// with the specified catalog and export providers. /// </summary> /// <param name="compositionSettings"> /// <see cref="CompositionOptions"/> enumeration with flags controlling the composition. /// </param> /// <param name="providers"> /// A <see cref="Array"/> of <see cref="ExportProvider"/> objects which provide /// the <see cref="CompositionContainer"/> access to <see cref="Export"/> objects, /// or <see langword="null"/> to set <see cref="Providers"/> to an empty /// <see cref="ReadOnlyCollection{T}"/>. /// </param> /// <exception cref="ArgumentException"> /// <paramref name="providers"/> contains an element that is <see langword="null"/>. /// </exception> public CompositionContainer(ComposablePartCatalog catalog, CompositionOptions compositionOptions, params ExportProvider[] providers) { if (compositionOptions > (CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe | CompositionOptions.ExportCompositionService)) { throw new ArgumentOutOfRangeException("compositionOptions"); } _compositionOptions = compositionOptions; // We always create the mutable provider _partExportProvider = new ComposablePartExportProvider(compositionOptions); _partExportProvider.SourceProvider = this; // Create the catalog export provider, only if necessary if (catalog != null) { _catalogExportProvider = new CatalogExportProvider(catalog, compositionOptions); _catalogExportProvider.SourceProvider = this; } // Set the local export provider if (_catalogExportProvider != null) { _localExportProvider = new AggregateExportProvider(_partExportProvider, _catalogExportProvider); _disposableLocalExportProvider = _localExportProvider as IDisposable; } else { _localExportProvider = _partExportProvider; } // Set the ancestor export provider, if ancestors are supplied if ((providers != null) && (providers.Length > 0)) { // Aggregate ancestors if and only if more than one passed if (providers.Length > 1) { _ancestorExportProvider = new AggregateExportProvider(providers); _disposableAncestorExportProvider = _ancestorExportProvider as IDisposable; } else { if (providers[0] == null) { throw ExceptionBuilder.CreateContainsNullElement("providers"); } _ancestorExportProvider = providers[0]; } } // finally set the root provider if (_ancestorExportProvider == null) { // if no ancestors are passed, the local and the root are the same _rootProvider = _localExportProvider; } else { int exportProviderCount = 1 + ((catalog != null) ? 1 : 0) + ((providers != null) ? providers.Length : 0); ExportProvider[] rootProviders = new ExportProvider[exportProviderCount]; rootProviders[0] = _partExportProvider; int customProviderStartIndex = 1; if (catalog != null) { rootProviders[1] = _catalogExportProvider; customProviderStartIndex = 2; } if (providers != null) { for (int i = 0; i < providers.Length; i++) { rootProviders[customProviderStartIndex + i] = providers[i]; } } _rootProvider = new AggregateExportProvider(rootProviders); _disposableRootProvider = _rootProvider as IDisposable; } //Insert Composition Service if (compositionOptions.HasFlag(CompositionOptions.ExportCompositionService)) { this.ComposeExportedValue <ICompositionService>(new CompositionServiceShim(this)); } _rootProvider.ExportsChanged += OnExportsChangedInternal; _rootProvider.ExportsChanging += OnExportsChangingInternal; _providers = (providers != null) ? new ReadOnlyCollection <ExportProvider>((ExportProvider[])providers.Clone()) : EmptyProviders; }
public NonSharedCatalogExport(CatalogExportProvider catalogExportProvider, ComposablePartDefinition partDefinition, ExportDefinition definition) : base(catalogExportProvider, partDefinition, definition) { }
public InnerCatalogExportProvider(CatalogExportProvider outerExportProvider) { Assumes.NotNull(outerExportProvider); _outerExportProvider = outerExportProvider; }
public void ComponentCatalogResolverGetStaticExport() { var catalog = CatalogFactory.CreateDefaultAttributed(); var catalogExportProvider = new CatalogExportProvider(catalog); catalogExportProvider.SourceProvider = catalogExportProvider; var exports = catalogExportProvider.GetExports(ImportFromContract("StaticString")); Assert.AreEqual(1, exports.Count()); Assert.AreEqual("StaticString", exports.First().Value); }