当前位置: 首页>>代码示例>>C#>>正文


C# Hosting.ExportProvider类代码示例

本文整理汇总了C#中System.ComponentModel.Composition.Hosting.ExportProvider的典型用法代码示例。如果您正苦于以下问题:C# ExportProvider类的具体用法?C# ExportProvider怎么用?C# ExportProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExportProvider类属于System.ComponentModel.Composition.Hosting命名空间,在下文中一共展示了ExportProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Document

        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="catalog"></param>
        /// <param name="exports"></param>
        Document(
            Func<Document, XDocument> xml,
            ComposablePartCatalog catalog,
            ExportProvider exports)
        {
            Contract.Requires<ArgumentNullException>(xml != null);

            // configure composition
            this.configuration = GetConfiguration(catalog, exports);
            this.container = new CompositionContainer(configuration.HostCatalog, true, new CompositionContainer(configuration.GlobalCatalog, true, configuration.Exports));
            this.container.GetExportedValue<DocumentEnvironment>().SetHost(this);

            // required services
            this.invoker = container.GetExportedValue<IInvoker>();
            this.trace = container.GetExportedValue<ITraceService>();

            // initialize xml
            this.xml = xml(this);
            this.xml.AddAnnotation(this);

            // parallel initialization of common interfaces
            Parallel.ForEach(this.xml.DescendantNodesAndSelf(), i =>
            {
                Enumerable.Empty<object>()
                    .Concat(i.Interfaces<IOnInit>())
                    .Concat(i.Interfaces<IOnLoad>())
                    .ToLinkedList();
            });

            // initial invocation entry
            this.invoker.Invoke(() => { });
        }
开发者ID:nxkit,项目名称:nxkit,代码行数:38,代码来源:Document.cs

示例2: Configurate

        /// <summary>
        /// Configurates the specified export provider.
        /// </summary>
        /// <param name="exportProvider">The export provider.</param>
        /// <param name="loggerFactoryName">Name of the logger factory.</param>
        /// <exception cref="System.ArgumentNullException">exportProvider</exception>
        public static void Configurate(ExportProvider exportProvider, string loggerFactoryName = null)
        {
            if (exportProvider == null)
                throw new ArgumentNullException("exportProvider");

            var lazyLogFactory = exportProvider.GetExports<ILoggerFactory, ILoggerFactoryMetadata>()
                    .Where(f => string.IsNullOrEmpty(loggerFactoryName) || f.Metadata.Name.Equals(loggerFactoryName, StringComparison.OrdinalIgnoreCase))
                    .OrderBy(f => f.Metadata.Priority)
                    .FirstOrDefault();

            if (lazyLogFactory == null)
                return;

            var metadata = lazyLogFactory.Metadata;
            var configFiles = new List<string>();

            if (!string.IsNullOrEmpty(metadata.ConfigFileName))
            {
                configFiles.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, metadata.ConfigFileName));
                configFiles.Add(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config"), metadata.ConfigFileName));
            }

            var facotry = lazyLogFactory.Value;

            if (!facotry.Initialize(configFiles.ToArray()))
                return;

            m_Current = facotry;
        }
开发者ID:kerryjiang,项目名称:AnyLog,代码行数:35,代码来源:LoggerFactory.cs

示例3: ResolveAll

        /// <summary>
        /// Resolves an collection of objects wrapped inside <see cref="Lazy{T}"/>
        /// from an <see cref="ExportProvider"/>.
        /// </summary>
        /// <param name="exportProvider">Export provider.</param>
        /// <param name="type">Type to be resolved.</param>
        /// <param name="name">Optional name.</param>
        /// <returns>Resolved collection of lazy instances or null, if no instance has been found.</returns>
        /// <remarks>
        /// Does not resolve instances which are provided by means of
        /// <see cref="FactoryExportProvider"/>.
        /// </remarks>
        public static IEnumerable<Lazy<object>> ResolveAll(ExportProvider exportProvider, Type type, string name)
        {
            if (exportProvider == null)
            {
                throw new ArgumentNullException("exportProvider");
            }

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var exports = exportProvider.GetExports(type, null, name);

            if (exports.Count() == 0)
                return Enumerable.Empty<Lazy<object>>();
            
            var list = new List<Lazy<object>>();

            foreach (var export in exports)
            {
                var lazyExportMetadata = export.Metadata as IDictionary<string, object>;
                if (lazyExportMetadata != null &&
                    lazyExportMetadata.ContainsKey(FactoryExportDefinition.IsFactoryExportMetadataName) &&
                    true.Equals(lazyExportMetadata[FactoryExportDefinition.IsFactoryExportMetadataName]))
                {
                    continue;
                }

                list.Add(export);
            }

            return list;
        }
开发者ID:doublekill,项目名称:MefContrib,代码行数:46,代码来源:ContainerServices.cs

示例4: AggregateExportProvider

        /// <summary>
        /// Initializes a new instance of the <see cref="AggregateExportProvider"/> class.
        /// </summary>
        /// <param name="providers">The prioritized list of export providers.</param>
        /// <exception cref="ArgumentException">
        ///     <paramref name="providers"/> contains an element that is <see langword="null"/>.
        /// </exception>
        /// <remarks>
        ///     <para>
        ///         The <see cref="AggregateExportProvider"/> will consult the providers in the order they have been specfied when 
        ///         executing <see cref="ExportProvider.GetExports(ImportDefinition,AtomicComposition)"/>. 
        ///     </para>
        ///     <para>
        ///         The <see cref="AggregateExportProvider"/> does not take ownership of the specified providers. 
        ///         That is, it will not try to dispose of any of them when it gets disposed.
        ///     </para>
        /// </remarks>
        public AggregateExportProvider(params ExportProvider[] providers) 
        {
            // NOTE : we optimize for the array case here, because the collection of providers is typically tiny
            // Arrays are much more compact to store and much faster to create and enumerate
            ExportProvider[] copiedProviders = null;
            if (providers != null)
            {
                copiedProviders = new ExportProvider[providers.Length];
                for (int i = 0; i < providers.Length; i++)
                {
                    ExportProvider provider = providers[i];
                    if (provider == null)
                    {
                        throw ExceptionBuilder.CreateContainsNullElement("providers");
                    }

                    copiedProviders[i] = provider;

                    provider.ExportsChanged += this.OnExportChangedInternal;
                    provider.ExportsChanging += this.OnExportChangingInternal;
                }
            }
            else
            {
                copiedProviders = new ExportProvider[] { };
            }

            this._providers = copiedProviders;
            this._readOnlyProviders = new ReadOnlyCollection<ExportProvider>(this._providers);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:47,代码来源:AggregateExportProvider.cs

示例5: Resolve

        /// <summary>
        /// Resolves an object wrapped inside <see cref="Lazy{T}"/> from an <see cref="ExportProvider"/>.
        /// </summary>
        /// <param name="exportProvider">Export provider.</param>
        /// <param name="type">Type to be resolved.</param>
        /// <param name="name">Optional name.</param>
        /// <returns>Resolved instance or null, if no instance has been found.</returns>
        /// <remarks>
        /// Does not resolve instances which are provided by means of
        /// <see cref="FactoryExportProvider"/>.
        /// </remarks>
        public static Lazy<object> Resolve(ExportProvider exportProvider, Type type, string name)
        {
            if (exportProvider == null)
            {
                throw new ArgumentNullException("exportProvider");
            }

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var exports = exportProvider.GetExports(type, null, name);

            if (exports.Count() == 0)
                return null;

            if (exports.Count() > 1)
                throw new ImportCardinalityMismatchException(Resources.TooManyInstances);

            var lazyExport = exports.First();
            var lazyExportMetadata = lazyExport.Metadata as IDictionary<string, object>;
            if (lazyExportMetadata != null &&
                lazyExportMetadata.ContainsKey(FactoryExportDefinition.IsFactoryExportMetadataName) &&
                true.Equals(lazyExportMetadata[FactoryExportDefinition.IsFactoryExportMetadataName]))
            {
                return null;
            }

            return lazyExport;
        }
开发者ID:doublekill,项目名称:MefContrib,代码行数:42,代码来源:ContainerServices.cs

示例6: GlimpseExportProvider

        /// <summary>
        /// Initialises a new instance of <see cref="GlimpseExportProvider"/>.
        /// </summary>
        /// <param name="provider">The inner export provider.</param>
        internal GlimpseExportProvider(ExportProvider provider)
        {
            if (provider == null)
                throw new ArgumentNullException("provider");

            _provider = provider;
        }
开发者ID:Antaris,项目名称:Glimpse.MEF,代码行数:11,代码来源:GlimpseExportProvider.cs

示例7: ImportEngine

        public ImportEngine(ExportProvider sourceProvider, bool isThreadSafe)
        {
            Requires.NotNull(sourceProvider, "sourceProvider");

            this._sourceProvider = sourceProvider;
            this._sourceProvider.ExportsChanging += this.OnExportsChanging;
            this._lock = new CompositionLock(isThreadSafe);
        }
开发者ID:GuySrinivasan,项目名称:mono,代码行数:8,代码来源:ImportEngine.cs

示例8: RazorVersionDetectorOverridingExportProvider

 public RazorVersionDetectorOverridingExportProvider(ExportProvider exportProvider)
 {
     _inner = exportProvider;
     _razorVersionDetectorExports = new[]
     {
         new Export(IRazorVersionDetectorName, DecorateRazorVersionDetector)
     };
 }
开发者ID:drivenet,项目名称:aspnetrazor,代码行数:8,代码来源:RazorVersionDetectorOverridingExportProvider.cs

示例9: CreateIndexes

		public static void CreateIndexes(ExportProvider catalogToGetnIndexingTasksFrom, IDocumentStore documentStore)
		{
			var tasks = catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>();
			foreach (var task in tasks)
			{
				task.Execute(documentStore);
			}
		}
开发者ID:ajaishankar,项目名称:ravendb,代码行数:8,代码来源:IndexCreation.cs

示例10: Initialize

        protected override void Initialize()
        {
            base.Initialize();

            _componentModel = (IComponentModel)GetService(typeof(SComponentModel));
            _exportProvider = _componentModel.DefaultExportProvider;
            _vim = _exportProvider.GetExportedValue<IVim>();
        }
开发者ID:aesire,项目名称:VsVim,代码行数:8,代码来源:VsVimPackage.cs

示例11: CreateIndexes

		/// <summary>
		/// Creates the indexes found in the specified catalog
		/// </summary>
		/// <param name="catalogToGetnIndexingTasksFrom">The catalog to get indexing tasks from.</param>
		public static void CreateIndexes(ExportProvider catalogToGetnIndexingTasksFrom, IDatabaseCommands databaseCommands, DocumentConvention conventions)
		{
			var tasks = catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>();
			foreach (var task in tasks)
			{
				task.Execute(databaseCommands, conventions);
			}
		}
开发者ID:neiz,项目名称:ravendb,代码行数:12,代码来源:IndexCreation.cs

示例12: RHistoryIntegrationTest

 public RHistoryIntegrationTest(RComponentsMefCatalogFixture catalog) {
     _exportProvider = catalog.CreateExportProvider();
     _textBufferFactory = _exportProvider.GetExportedValue<ITextBufferFactoryService>();
     _textEditorFactory = _exportProvider.GetExportedValue<ITextEditorFactoryService>();
     _workflowProvider = _exportProvider.GetExportedValue<IRInteractiveWorkflowProvider>();
     _contentTypeRegistryService = _exportProvider.GetExportedValue<IContentTypeRegistryService>();
     _interactiveWindowComponentContainerFactory = _exportProvider.GetExportedValue<IInteractiveWindowComponentContainerFactory>();
     _historyVisualComponentContainerFactory = _exportProvider.GetExportedValue<IRHistoryVisualComponentContainerFactory>();
 }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:9,代码来源:RHistoryIntegrationTest.cs

示例13: ImportEngine

        public ImportEngine(ExportProvider sourceProvider, CompositionOptions compositionOptions)
        {
            Requires.NotNull(sourceProvider, "sourceProvider");

            this._compositionOptions = compositionOptions;
            this._sourceProvider = sourceProvider;
            this._sourceProvider.ExportsChanging += this.OnExportsChanging;
            this._lock = new CompositionLock(compositionOptions.HasFlag(CompositionOptions.IsThreadSafe));
        }
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:ImportEngine.cs

示例14: CreateIndexesAsync

		/// <summary>
		/// Creates the indexes found in the specified catalog
		/// </summary>
		/// <param name="catalogToGetnIndexingTasksFrom">The catalog to getn indexing tasks from.</param>
		/// <param name="documentStore">The document store.</param>
		public static Task CreateIndexesAsync(ExportProvider catalogToGetnIndexingTasksFrom, IDocumentStore documentStore)
		{
			var tasks = catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>();

			Task[] array = tasks.Select(task => task.ExecuteAsync(documentStore)).ToArray();
			var indexesAsync = new Task(() => Task.WaitAll(array));
			indexesAsync.Start();
			return indexesAsync;
		}
开发者ID:aduggleby,项目名称:ravendb,代码行数:14,代码来源:IndexCreation.cs

示例15: Constructor3_ArrayAsProvidersArgument_ShouldNotAllowModificationAfterConstruction

        public void Constructor3_ArrayAsProvidersArgument_ShouldNotAllowModificationAfterConstruction()
        {
            var providers = new ExportProvider[] { ExportProviderFactory.Create() };
            var container = new CompositionContainer(CatalogFactory.Create(), providers);

            providers[0] = null;

            Assert.IsNotNull(container.Providers[0]);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:CompositionContainerTests.cs


注:本文中的System.ComponentModel.Composition.Hosting.ExportProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。