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


C# IComponentContext.ResolveComponent方法代码示例

本文整理汇总了C#中IComponentContext.ResolveComponent方法的典型用法代码示例。如果您正苦于以下问题:C# IComponentContext.ResolveComponent方法的具体用法?C# IComponentContext.ResolveComponent怎么用?C# IComponentContext.ResolveComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IComponentContext的用法示例。


在下文中一共展示了IComponentContext.ResolveComponent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanSupplyValue

 /// <summary>
 /// Returns true if the parameter is able to provide a value to a particular site.
 /// </summary>
 /// <param name="pi">Constructor, method, or property-mutator parameter.</param>
 /// <param name="context">The component context in which the value is being provided.</param>
 /// <param name="valueProvider">If the result is true, the valueProvider parameter will
 /// be set to a function that will lazily retrieve the parameter value. If the result is false,
 /// will be set to null.</param>
 /// <returns>True if a value can be supplied; otherwise, false.</returns>
 public override bool CanSupplyValue(ParameterInfo pi, IComponentContext context, out Func<object> valueProvider)
 {
     IComponentRegistration registration;
     if (context.ComponentRegistry.TryGetRegistration(new TypedService(pi.ParameterType), out registration))
     {
         valueProvider = () => context.ResolveComponent(registration, Enumerable.Empty<Parameter>());
         return true;
     }
     valueProvider = null;
     return false;
 }
开发者ID:shiftkey,项目名称:bearded-dangerzone,代码行数:20,代码来源:AutowiringParameter.cs

示例2: StartStartableComponents

        static void StartStartableComponents(IComponentContext componentContext)
        {
            // We track which registrations have already been auto-activated by adding
            // a metadata value. If the value is present, we won't re-activate. This helps
            // in the container update situation.
            const string started = "__AutoActivated";
            object meta;

            foreach (var startable in componentContext.ComponentRegistry.RegistrationsFor(new TypedService(typeof(IStartable))).Where(r => !r.Metadata.TryGetValue(started, out meta)))
            {
                try
                {
                    var instance = (IStartable)componentContext.ResolveComponent(startable, Enumerable.Empty<Parameter>());
                    instance.Start();
                }
                finally
                {
                    startable.Metadata[started] = true;
                }
            }

            foreach (var registration in componentContext.ComponentRegistry.RegistrationsFor(new AutoActivateService()).Where(r => !r.Metadata.TryGetValue(started, out meta)))
            {
                try
                {
                    componentContext.ResolveComponent(registration, Enumerable.Empty<Parameter>());
                }
                catch (DependencyResolutionException ex)
                {
                    throw new DependencyResolutionException(String.Format(CultureInfo.CurrentCulture, ContainerBuilderResources.ErrorAutoActivating, registration), ex);
                }
                finally
                {
                    registration.Metadata[started] = true;
                }
            }
        }
开发者ID:kcuzner,项目名称:Autofac,代码行数:37,代码来源:ContainerBuilder.cs

示例3: StartStartableComponents

 static void StartStartableComponents(IComponentContext componentContext)
 {
     var ts = new TypedService(typeof(IStartable));
     foreach (var startable in componentContext.ComponentRegistry.RegistrationsFor(ts))
     {
         var instance = (IStartable)componentContext.ResolveComponent(ts, startable, Enumerable.Empty<Parameter>());
         instance.Start();
     }
 }
开发者ID:ngs-doo,项目名称:revenj,代码行数:9,代码来源:ContainerBuilder.cs


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