• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CompositionContract类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: GetExportDescriptors

        public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
        {
            // Avoid trying to create defaults-of-defaults-of...
            if (contract.ContractName != null && contract.ContractName.StartsWith(Constants.DefaultContractNamePrefix))
                return NoExportDescriptors;

            var implementations = descriptorAccessor.ResolveDependencies("test for default", contract, false);
            if (implementations.Any())
                return NoExportDescriptors;

            var defaultImplementationDiscriminator = Constants.DefaultContractNamePrefix + (contract.ContractName ?? "");
            IDictionary<string, object> copiedConstraints = null;
            if (contract.MetadataConstraints != null)
                copiedConstraints = contract.MetadataConstraints.ToDictionary(k => k.Key, k => k.Value);
            var defaultImplementationContract = new CompositionContract(contract.ContractType, defaultImplementationDiscriminator, copiedConstraints);

            CompositionDependency defaultImplementation;
            if (!descriptorAccessor.TryResolveOptionalDependency("default", defaultImplementationContract, true, out defaultImplementation))
                return NoExportDescriptors;

            return new[]
            {
                new ExportDescriptorPromise(
                    contract,
                    "Default Implementation",
                    false,
                    () => new[] {defaultImplementation},
                    _ =>
                    {
                        var defaultDescriptor = defaultImplementation.Target.GetDescriptor();
                        return ExportDescriptor.Create((c, o) => defaultDescriptor.Activator(c, o), defaultDescriptor.Metadata);
                    })
            };
        }
开发者ID:pglazkov,项目名称:Linqua,代码行数:34,代码来源:DefaultExportDescriptorProvider.cs


示例2: GetExportDescriptors

        /// <summary>
        /// <see cref="ILogger"/>生成処理
        /// 
        /// https://mef.codeplex.com/wikipage?title=ProgrammingModelExtensions&referringTitle=Documentation
        /// </summary>
        /// <param name="contract"></param>
        /// <param name="descriptorAccessor"></param>
        /// <returns></returns>
        public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
        {
            if (contract.ContractType == typeof(ILogger))
            {
                string value = string.Empty;
                CompositionContract unwrap;

                contract.TryUnwrapMetadataConstraint("LogType", out value, out unwrap);

                string header = string.Format("[{0}] LogExportDescriptorProvider - ", value);

                return new ExportDescriptorPromise[]
                {
                    new ExportDescriptorPromise(
                        contract,
                        "ConsoleMef2 ILogger",
                        true,
                        NoDependencies,
                        _ => ExportDescriptor.Create((c, o) => new Logger() { Header = header },  NoMetadata)
                    )
                };
            }
            else
                return NoExportDescriptors;
        }
开发者ID:yasu-s,项目名称:MEF-Sample,代码行数:33,代码来源:LogExportDescriptorProvider.cs


示例3: GetExportDescriptors

        public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(
            CompositionContract contract,
            DependencyAccessor dependencyAccessor)
        {
            if (contract == null) throw new ArgumentNullException("contract");
            if (dependencyAccessor == null) throw new ArgumentNullException("dependencyAccessor");

            string key;
            CompositionContract unwrapped;

            if (!contract.TryUnwrapMetadataConstraint(SettingKey, out key, out unwrapped) ||
                !unwrapped.Equals(new CompositionContract(unwrapped.ContractType)) ||
                !SupportedSettingTypes.Contains(unwrapped.ContractType) ||
                !ConfigurationManager.AppSettings.AllKeys.Contains(key))
                yield break;

            var value = ConfigurationManager.AppSettings.Get(key);
            var converted = Convert.ChangeType(value, contract.ContractType);

            yield return new ExportDescriptorPromise(
                    contract,
                    "System.Configuration.ConfigurationManager.AppSettings",
                    true,
                    NoDependencies,
                    _ => ExportDescriptor.Create((c, o) => converted, NoMetadata));
        }
开发者ID:blinds52,项目名称:alt-composition,代码行数:26,代码来源:SettingsExportDescriptorProvider.cs


示例4: GetExportDescriptors

        /// <summary>
        /// Promise export descriptors for the specified export key.
        /// </summary>
        /// <param name="contract">The export key required by another component.</param><param name="descriptorAccessor">Accesses the other export descriptors present in the composition.</param>
        /// <returns>
        /// Promises for new export descriptors.
        /// </returns>
        /// <remarks>
        /// A provider will only be queried once for each unique export key.
        ///             The descriptor accessor can only be queried immediately if the descriptor being promised is an adapter, such as
        ///             <see cref="T:System.Lazy`1"/>; otherwise, dependencies should only be queried within execution of the function provided
        ///             to the <see cref="T:System.Composition.Hosting.Core.ExportDescriptorPromise"/>. The actual descriptors provided should not close over or reference any
        ///             aspect of the dependency/promise structure, as this should be able to be GC'ed.
        /// </remarks>
        public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
        {
            var isSupported = this.servicesSupport.GetOrAdd(
                contract.ContractType,
                type => this.serviceProvider.GetService(type) != null);

            if (!isSupported)
            {
                return ExportDescriptorProvider.NoExportDescriptors;
            }

            return new[]
               {
                 new ExportDescriptorPromise(
                   contract,
                   contract.ContractType.Name,
                   true, // is shared
                   ExportDescriptorProvider.NoDependencies,
                   dependencies => ExportDescriptor.Create(
                     (c, o) =>
                       {
                       var instance = this.serviceProvider.GetService(contract.ContractType);
                       var disposable = instance as IDisposable;
                       if (disposable != null)
                       {
                         c.AddBoundInstance(disposable);
                       }

                       return instance;
                     }, 
                     ExportDescriptorProvider.NoMetadata))
               };
        }
开发者ID:raimu,项目名称:kephas,代码行数:47,代码来源:ServiceProviderExportDescriptorProvider.cs


示例5: TryGetSingleForExport

        public bool TryGetSingleForExport(CompositionContract exportKey, out ExportDescriptor defaultForExport)
        {
            ExportDescriptor[] allForExport;
            if (!_partDefinitions.TryGetValue(exportKey, out allForExport))
            {
                lock (_thisLock)
                {
                    if (!_partDefinitions.ContainsKey(exportKey))
                    {
                        var updatedDefinitions = new Dictionary<CompositionContract, ExportDescriptor[]>(_partDefinitions);
                        var updateOperation = new ExportDescriptorRegistryUpdate(updatedDefinitions, _exportDescriptorProviders);
                        updateOperation.Execute(exportKey);

                        _partDefinitions = updatedDefinitions;
                    }
                }

                allForExport = (ExportDescriptor[])_partDefinitions[exportKey];
            }

            if (allForExport.Length == 0)
            {
                defaultForExport = null;
                return false;
            }

            // This check is duplicated in the update process- the update operation will catch
            // cardinality violations in advance of this in all but a few very rare scenarios.
            if (allForExport.Length != 1)
                throw ThrowHelper.CardinalityMismatch_TooManyExports(exportKey.ToString());

            defaultForExport = allForExport[0];
            return true;
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:34,代码来源:ExportDescriptorRegistry.cs


示例6: CompositionDependency

 private CompositionDependency(CompositionContract contract, ExportDescriptorPromise target, bool isPrerequisite, object site)
 {
     _target = target;
     _isPrerequisite = isPrerequisite;
     _site = site;
     _contract = contract;
 }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:7,代码来源:CompositionDependency.cs


示例7: GetExportDescriptors

        public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
        {
            if (contract == null) throw new ArgumentNullException("contract");
            if (descriptorAccessor == null) throw new ArgumentNullException("descriptorAccessor");

            string name;
            CompositionContract unwrapped;

            var connectionStringSettings = ConfigurationManager.ConnectionStrings.OfType<ConnectionStringSettings>().ToArray();

            if (!contract.TryUnwrapMetadataConstraint(NameKey, out name, out unwrapped) ||
                !unwrapped.Equals(new CompositionContract(unwrapped.ContractType)) ||
                !(unwrapped.ContractType == typeof(string) || typeof(DbConnectionStringBuilder).IsAssignableFrom(unwrapped.ContractType)) ||
                !connectionStringSettings.Any(cs => cs.Name == name))
                yield break;

            var stringValue = connectionStringSettings.Single(cs => cs.Name == name).ConnectionString;
            object value = stringValue;

            if (contract.ContractType != typeof(string))
            {
                var stringBuilder = Activator.CreateInstance(contract.ContractType) as DbConnectionStringBuilder;
                if (stringBuilder == null) yield break;
                stringBuilder.ConnectionString = stringValue;
                value = stringBuilder;
            }

            yield return new ExportDescriptorPromise(
                    contract,
                    "System.Configuration.ConfigurationManager.ConnectionStrings",
                    true,
                    NoDependencies,
                    _ => ExportDescriptor.Create((c, o) => value, NoMetadata));
        }
开发者ID:blinds52,项目名称:alt-composition,代码行数:34,代码来源:ConnectionStringsExportDescriptorProvider.cs


示例8: Missing

        /// <summary>
        /// Construct a placeholder for a missing dependency. Note that this is different
        /// from an optional dependency - a missing dependency is an error.
        /// </summary>
        /// <param name="site">A marker used to identify the individual dependency among
        /// those on the dependent part.</param>
        /// <param name="contract">The contract required by the dependency.</param>
        public static CompositionDependency Missing(CompositionContract contract, object site)
        {
            Requires.NotNull(contract, nameof(contract));
            Requires.NotNull(site, nameof(site));

            return new CompositionDependency(contract, site);
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:14,代码来源:CompositionDependency.cs


示例9: ChangingTheTypeOfAContractPreservesTheContractName

 public void ChangingTheTypeOfAContractPreservesTheContractName()
 {
     var name = "a";
     var c = new CompositionContract(typeof(object), name);
     var d = c.ChangeType(typeof(AType));
     Assert.Equal(name, d.ContractName);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:ContractTests.cs


示例10: ResolveRequiredDependency

        /// <summary>
        /// Resolve a required dependency on exactly one implemenation of a contract.
        /// </summary>
        /// <param name="site">A tag describing the dependency site.</param>
        /// <param name="contract">The contract required by the site.</param>
        /// <param name="isPrerequisite">True if the dependency must be satisifed before corresponding exports can be retrieved; otherwise, false.</param>
        /// <returns>The dependency.</returns>
        public CompositionDependency ResolveRequiredDependency(object site, CompositionContract contract, bool isPrerequisite)
        {
            CompositionDependency result;
            if (!TryResolveOptionalDependency(site, contract, isPrerequisite, out result))
                return CompositionDependency.Missing(contract, site);

            return result;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:DependencyAccessor.cs


示例11: Oversupplied

        /// <summary>
        /// Construct a placeholder for an "exactly one" dependency that cannot be
        /// configured because multiple target implementations exist.
        /// </summary>
        /// <param name="site">A marker used to identify the individual dependency among
        /// those on the dependent part.</param>
        /// <param name="targets">The targets found when expecting only one.</param>
        /// <param name="contract">The contract required by the dependency.</param>
        public static CompositionDependency Oversupplied(CompositionContract contract, IEnumerable<ExportDescriptorPromise> targets, object site)
        {
            Requires.NotNull(targets, nameof(targets));
            Requires.NotNull(site, nameof(site));
            Requires.NotNull(contract, nameof(contract));

            return new CompositionDependency(contract, targets, site);
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:16,代码来源:CompositionDependency.cs


示例12: Satisfied

        /// <summary>
        /// Construct a dependency on the specified target.
        /// </summary>
        /// <param name="target">The export descriptor promise from another part
        /// that this part is dependent on.</param>
        /// <param name="isPrerequisite">True if the dependency is a prerequisite
        /// that must be satisfied before any exports can be retrieved from the dependent
        /// part; otherwise, false.</param>
        /// <param name="site">A marker used to identify the individual dependency among
        /// those on the dependent part.</param>
        /// <param name="contract">The contract required by the dependency.</param>
        public static CompositionDependency Satisfied(CompositionContract contract, ExportDescriptorPromise target, bool isPrerequisite, object site)
        {
            Requires.NotNull(target, nameof(target));
            Requires.NotNull(site, nameof(site));
            Requires.NotNull(contract, nameof(contract));

            return new CompositionDependency(contract, target, isPrerequisite, site);
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:19,代码来源:CompositionDependency.cs


示例13: ResolveDependencies

 /// <summary>
 /// Resolve dependencies on all implementations of a contract.
 /// </summary>
 /// <param name="site">A tag describing the dependency site.</param>
 /// <param name="contract">The contract required by the site.</param>
 /// <param name="isPrerequisite">True if the dependency must be satisifed before corresponding exports can be retrieved; otherwise, false.</param>
 /// <returns>Dependencies for all implementations of the contact.</returns>
 public IEnumerable<CompositionDependency> ResolveDependencies(object site, CompositionContract contract, bool isPrerequisite)
 {
     var all = GetPromises(contract).ToArray();
     var result = new CompositionDependency[all.Length];
     for (var i = 0; i < all.Length; ++i)
         result[i] = CompositionDependency.Satisfied(contract, all[i], isPrerequisite, site);
     return result;
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:DependencyAccessor.cs


示例14: GetExportDescriptors

		public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors( CompositionContract contract, DependencyAccessor descriptorAccessor )
		{
			// var type = convention( contract.ContractType ) ?? contract.ContractType;
			contract.ContractType
					.Append( convention( contract.ContractType ) )
					.WhereAssigned()
					.Distinct()
					.Each( Initializer );
			yield break;
		}
开发者ID:DevelopersWin,项目名称:VoteReporter,代码行数:10,代码来源:TypeInitializingExportDescriptorProvider.cs


示例15: GetExportDescriptors

            public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
            {
                if (!contract.Equals(_supportedContract))
                    return NoExportDescriptors;

                var implementations = descriptorAccessor.ResolveDependencies("test for existing", contract, false);
                if (implementations.Any())
                    return NoExportDescriptors;

                return new[] { new ExportDescriptorPromise(contract, "test metadataProvider", false, NoDependencies, _ => ExportDescriptor.Create((c, o) => DefaultObject, NoMetadata)) };
            }
开发者ID:ChuangYang,项目名称:corefx,代码行数:11,代码来源:ExportDescriptorProviderTests.cs


示例16: ConstraintsCanBeAppliedToGenerics

        public void ConstraintsCanBeAppliedToGenerics()
        {
            var contract = new CompositionContract(typeof(SomeSetting<string>), null, new Dictionary<string, object>
            {
                { "SettingName", "TheName" }
            });

            var c = CreateContainer(typeof(SomeSetting<>));
            object s;
            Assert.True(c.TryGetExport(contract, out s));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:11,代码来源:MetadataConstraintTests.cs


示例17: MefDependencyResolver

        public MefDependencyResolver(CompositionHost rootCompositionScope) : base(new Export<CompositionContext>(rootCompositionScope, rootCompositionScope.Dispose)) {

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

            var factoryContract = new CompositionContract(typeof(ExportFactory<CompositionContext>), null, new Dictionary<string, object> {
                { "SharingBoundaryNames", new[] { "HttpRequest" } }
            });

            this.RequestScopeFactory = (ExportFactory<CompositionContext>)rootCompositionScope.GetExport(factoryContract);
        }
开发者ID:sourcemax,项目名称:SourceMax.Web.IoC,代码行数:12,代码来源:MefDependencyResolver.cs


示例18: GetExportDescriptors

        public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor definitionAccessor)
        {
            if (!contract.Equals(s_currentScopeContract))
                return NoExportDescriptors;

            return new[] { new ExportDescriptorPromise(
                contract,
                typeof(CompositionContext).Name,
                true,
                NoDependencies,
                _ => ExportDescriptor.Create((c, o) => c, NoMetadata)) };
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:12,代码来源:CurrentScopeExportDescriptorProvider.cs


示例19: ExportDescriptorPromise

 /// <summary>
 /// Create a promise for an export descriptor.
 /// </summary>
 /// <param name="origin">A description of where the export is being provided from (e.g. the part type).
 /// Used to provide friendly errors.</param>
 /// <param name="isShared">True if the export is shared within some context, otherwise false. Used in cycle
 /// checking.</param>
 /// <param name="dependencies">A function providing dependencies required in order to fulfill the promise.</param>
 /// <param name="getDescriptor">A function providing the promise.</param>
 /// <param name="contract">The contract fulfilled by this promise.</param>
 /// <seealso cref="ExportDescriptorProvider"/>.
 public ExportDescriptorPromise(
     CompositionContract contract,
     string origin,
     bool isShared,
     Func<IEnumerable<CompositionDependency>> dependencies,
     Func<IEnumerable<CompositionDependency>, ExportDescriptor> getDescriptor)
 {
     _contract = contract;
     _origin = origin;
     _isShared = isShared;
     _dependencies = new Lazy<ReadOnlyCollection<CompositionDependency>>(() => new ReadOnlyCollection<CompositionDependency>(dependencies().ToList()), false);
     _descriptor = new Lazy<ExportDescriptor>(() => getDescriptor(_dependencies.Value), false);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:24,代码来源:ExportDescriptorPromise.cs


示例20: AddDiscoveredExport

        private void AddDiscoveredExport(DiscoveredExport export, CompositionContract contract = null)
        {
            var actualContract = contract ?? export.Contract;

            ICollection<DiscoveredExport> forKey;
            if (!_discoveredParts.TryGetValue(actualContract, out forKey))
            {
                forKey = new List<DiscoveredExport>();
                _discoveredParts.Add(actualContract, forKey);
            }

            forKey.Add(export);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:13,代码来源:TypedPartExportDescriptorProvider.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Compositor类代码示例发布时间:2022-05-24
下一篇:
C# CompositeType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap