本文整理汇总了C#中CreationContext.HandlerIsCurrentlyBeingResolved方法的典型用法代码示例。如果您正苦于以下问题:C# CreationContext.HandlerIsCurrentlyBeingResolved方法的具体用法?C# CreationContext.HandlerIsCurrentlyBeingResolved怎么用?C# CreationContext.HandlerIsCurrentlyBeingResolved使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CreationContext
的用法示例。
在下文中一共展示了CreationContext.HandlerIsCurrentlyBeingResolved方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanResolvePendingDependencies
private bool CanResolvePendingDependencies(CreationContext context)
{
// detect circular dependencies
if (context.HandlerIsCurrentlyBeingResolved(this))
return false;
foreach (Type service in DependenciesByService.Keys)
{
// a self-dependency is not allowed
var handler = Kernel.GetHandler(service);
if (handler == this)
return false;
// ask the kernel
if (!Kernel.HasComponent(service))
return false;
}
return DependenciesByKey.Count == 0;
}
示例2: HasComponentInValidState
private bool HasComponentInValidState(CreationContext context, Type service)
{
IHandler[] handlers = kernel.GetHandlers(service);
foreach (IHandler handler in handlers)
{
if (context == null || context.HandlerIsCurrentlyBeingResolved(handler) == false)
return IsHandlerInValidState(handler);
}
return false;
}
示例3: TryGetHandlerFromKernel
private IHandler TryGetHandlerFromKernel(DependencyModel dependency, CreationContext context)
{
// we are doing it in two stages because it is likely to be faster to a lookup
// by key than a linear search
IHandler handler = kernel.GetHandler(dependency.TargetType);
if (context.HandlerIsCurrentlyBeingResolved(handler) == false)
return handler;
// make a best effort to find another one that fit
IHandler[] handlers = kernel.GetHandlers(dependency.TargetType);
foreach(IHandler maybeCorrectHandler in handlers)
{
if (context.HandlerIsCurrentlyBeingResolved(maybeCorrectHandler) == false)
{
handler = maybeCorrectHandler;
break;
}
}
return handler;
}
示例4: ResolveServiceDependency
protected virtual object ResolveServiceDependency(CreationContext context, ComponentModel model,
DependencyModel dependency)
{
IHandler handler = null;
if (dependency.DependencyType == DependencyType.Service)
{
ParameterModel parameter = ObtainParameterModelMatchingDependency(dependency, model);
if (parameter != null)
{
// User wants to override, we then
// change the type to ServiceOverride
dependency.DependencyKey = ExtractComponentKey(parameter.Value, parameter.Name);
dependency.DependencyType = DependencyType.ServiceOverride;
}
}
if (dependency.TargetType == typeof(IKernel))
{
return kernel;
}
else
{
if (dependency.DependencyType == DependencyType.ServiceOverride)
{
handler = kernel.GetHandler(dependency.DependencyKey);
}
else
{
IHandler[] handlers = kernel.GetHandlers(dependency.TargetType);
foreach (IHandler maybeCorrectHandler in handlers)
{
if (context.HandlerIsCurrentlyBeingResolved(maybeCorrectHandler) == false)
{
handler = maybeCorrectHandler;
break;
}
}
if (handler == null)
{
throw new DependencyResolverException(
"Cycle detected in configuration.\r\n" +
"Component " + model.Name + " has a dependency on " +
dependency.TargetType + ", but it doesn't provide an override.\r\n" +
"You must provide an override if a component " +
"has a dependency on a service that it - itself - provides");
}
}
}
if (handler == null) return null;
context = RebuildContextForParameter(context, dependency.TargetType);
return handler.Resolve(context);
}