本文整理汇总了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;
}
示例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;
}
}
}
示例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();
}
}