本文整理汇总了C#中ISubDependencyResolver.CanResolve方法的典型用法代码示例。如果您正苦于以下问题:C# ISubDependencyResolver.CanResolve方法的具体用法?C# ISubDependencyResolver.CanResolve怎么用?C# ISubDependencyResolver.CanResolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISubDependencyResolver
的用法示例。
在下文中一共展示了ISubDependencyResolver.CanResolve方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanResolve
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
DependencyModel dependency)
{
return dependency.TargetType == typeof(IBookStore) && contextHandlerResolver.CanResolve(context, contextHandlerResolver, model,
new DependencyModel(typeof(IBookStore).FullName,
typeof(IBookStore), false));
}
示例2: CanResolve
/// <summary>
/// Returns true if the resolver is able to satisfy the specified dependency.
/// </summary>
/// <param name="context">Creation context, which is a resolver itself</param>
/// <param name="contextHandlerResolver">Parent resolver</param>
/// <param name="model">Model of the component that is requesting the dependency</param>
/// <param name="dependency">The dependency model</param>
/// <returns><c>true</c> if the dependency can be satisfied</returns>
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
DependencyModel dependency)
{
// 1 - check for the dependency on CreationContext, if present
if (context != null)
{
if (context.CanResolve(context, contextHandlerResolver, model, dependency))
{
return true;
}
}
// 2 - check with the model's handler, if not the same as the parent resolver
IHandler handler = kernel.GetHandler(model.Name);
if (handler != null && handler != contextHandlerResolver)
{
if (handler.CanResolve(context, contextHandlerResolver, model, dependency))
{
return true;
}
}
// 3 - check within parent resolver, if present
if (contextHandlerResolver != null)
{
if (contextHandlerResolver.CanResolve(context, contextHandlerResolver, model, dependency))
{
return true;
}
}
// 4 - check within subresolvers
foreach(ISubDependencyResolver subResolver in subResolvers)
{
if (subResolver.CanResolve(context, contextHandlerResolver, model, dependency))
{
return true;
}
}
// 5 - normal flow, checking against the kernel
if (dependency.DependencyType == DependencyType.Service ||
dependency.DependencyType == DependencyType.ServiceOverride)
{
return CanResolveServiceDependency(context, model, dependency);
}
else
{
return CanResolveParameterDependency(model, dependency);
}
}
示例3: Resolve
/// <summary>
/// Try to resolve the dependency by checking the parameters in
/// the model or checking the Kernel for the requested service.
/// </summary>
/// <remarks>
/// The dependency resolver has the following precedence order:
/// <list type="bullet">
/// <item><description>
/// The dependency is checked within the <see cref="CreationContext"/>
/// </description></item>
/// <item><description>
/// The dependency is checked within the <see cref="IHandler"/> instance for the component
/// </description></item>
/// <item><description>
/// The dependency is checked within the registered <see cref="ISubDependencyResolver"/>s
/// </description></item>
/// <item><description>
/// Finally the resolver tries the normal flow
/// which is using the configuration
/// or other component to satisfy the dependency
/// </description></item>
/// </list>
/// </remarks>
/// <param name="context">Creation context, which is a resolver itself</param>
/// <param name="contextHandlerResolver">Parent resolver</param>
/// <param name="model">Model of the component that is requesting the dependency</param>
/// <param name="dependency">The dependency model</param>
/// <returns>The dependency resolved value or null</returns>
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
DependencyModel dependency)
{
object value = null;
bool resolved = false;
// 1 - check for the dependency on CreationContext, if present
if (context != null)
{
if (context.CanResolve(context, contextHandlerResolver, model, dependency))
{
value = context.Resolve(context, contextHandlerResolver, model, dependency);
resolved = true;
}
}
// 2 - check with the model's handler, if not the same as the parent resolver
IHandler handler = kernel.GetHandler(model.Name);
if (!resolved && handler != contextHandlerResolver)
{
if (handler.CanResolve(context, contextHandlerResolver, model, dependency))
{
value = handler.Resolve(context, contextHandlerResolver, model, dependency);
resolved = true;
}
}
// 3 - check within parent resolver, if present
if (!resolved && contextHandlerResolver != null)
{
if (contextHandlerResolver.CanResolve(context, contextHandlerResolver, model, dependency))
{
value = contextHandlerResolver.Resolve(context, contextHandlerResolver, model, dependency);
resolved = true;
}
}
// 4 - check within subresolvers
if (!resolved)
{
foreach (ISubDependencyResolver subResolver in subResolvers)
{
if (subResolver.CanResolve(context, contextHandlerResolver, model, dependency))
{
value = subResolver.Resolve(context, contextHandlerResolver, model, dependency);
resolved = true;
break;
}
}
}
// 5 - normal flow, checking against the kernel
if (!resolved)
{
if (dependency.DependencyType == DependencyType.Service ||
dependency.DependencyType == DependencyType.ServiceOverride)
{
value = ResolveServiceDependency(context, model, dependency);
}
else
{
value = ResolveParameterDependency(context, model, dependency);
}
}
//.........这里部分代码省略.........
示例4: CanResolveFromContextHandlerResolver
private bool CanResolveFromContextHandlerResolver(CreationContext context, ISubDependencyResolver contextHandlerResolver,
ComponentModel model, DependencyModel dependency)
{
return contextHandlerResolver != null && contextHandlerResolver.CanResolve(context, contextHandlerResolver, model, dependency);
}
示例5: CanResolve
/// <summary>
/// Returns true if the resolver is able to satisfy the specified dependency.
/// </summary>
/// <param name = "context">Creation context, which is a resolver itself</param>
/// <param name = "contextHandlerResolver">Parent resolver</param>
/// <param name = "model">Model of the component that is requesting the dependency</param>
/// <param name = "dependency">The dependency model</param>
/// <returns>
/// <c>true</c>
/// if the dependency can be satisfied</returns>
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
{
// 1 - check for the dependency on CreationContext, if present
if (context != null && context.CanResolve(context, contextHandlerResolver, model, dependency))
{
return true;
}
// 2 - check with the model's handler, if not the same as the parent resolver
var handler = kernel.GetHandler(model.Name);
if (handler != null && handler != contextHandlerResolver && handler.CanResolve(context, contextHandlerResolver, model, dependency))
{
return true;
}
// 3 - check within parent resolver, if present
if (contextHandlerResolver != null && contextHandlerResolver.CanResolve(context, contextHandlerResolver, model, dependency))
{
return true;
}
// 4 - check within subresolvers
if (subResolvers.Count > 0)
{
if (subResolvers.Any(s => s.CanResolve(context, contextHandlerResolver, model, dependency)))
{
return true;
}
}
// 5 - normal flow, checking against the kernel
return CanResolveCore(context, model, dependency);
}
示例6: ResolveCore
private object ResolveCore(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
{
// 1 - check for the dependency on CreationContext, if present
if (context != null && context.CanResolve(context, contextHandlerResolver, model, dependency))
{
return context.Resolve(context, contextHandlerResolver, model, dependency);
}
// 2 - check with the model's handler, if not the same as the parent resolver
var handler = kernel.GetHandler(model.Name);
if (handler != contextHandlerResolver && handler.CanResolve(context, contextHandlerResolver, model, dependency))
{
return handler.Resolve(context, contextHandlerResolver, model, dependency);
}
// 3 - check within parent resolver, if present
if (contextHandlerResolver != null && contextHandlerResolver.CanResolve(context, contextHandlerResolver, model, dependency))
{
return contextHandlerResolver.Resolve(context, contextHandlerResolver, model, dependency);
}
// 4 - check within subresolvers
if (subResolvers.Count > 0)
{
for (var index = 0; index < subResolvers.Count; index++)
{
var subResolver = subResolvers[index];
if (subResolver.CanResolve(context, contextHandlerResolver, model, dependency))
{
return subResolver.Resolve(context, contextHandlerResolver, model, dependency);
}
}
}
// 5 - normal flow, checking against the kernel
return ResolveCore(context, model, dependency);
}