本文整理汇总了C#中IDependencyResolver.CanResolve方法的典型用法代码示例。如果您正苦于以下问题:C# IDependencyResolver.CanResolve方法的具体用法?C# IDependencyResolver.CanResolve怎么用?C# IDependencyResolver.CanResolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDependencyResolver
的用法示例。
在下文中一共展示了IDependencyResolver.CanResolve方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObtainPropertyValue
/// <summary>
/// Source: http://www.symbolsource.org/Public/Metadata/NuGet/Project/Castle.Windsor/3.0.0.3001/Release/.NETFramework,Version%3Dv4.0,Profile%3DClient/Castle.Windsor/Castle.Windsor/MicroKernel/ComponentActivator/DefaultComponentActivator.cs?ImageName=Castle.Windsor
/// </summary>
/// <param name="context"></param>
/// <param name="property"></param>
/// <param name="resolver"></param>
/// <returns></returns>
private object ObtainPropertyValue(CreationContext context, PropertySet property, IDependencyResolver resolver)
{
if (property.Dependency.IsOptional == false || resolver.CanResolve(context, context.Handler, Model, property.Dependency))
{
try
{
return resolver.Resolve(context, context.Handler, Model, property.Dependency);
}
catch (Exception ex)
{
//trondr: Do not silently ignore exceptions when resolving property depencies.
//if (property.Dependency.IsOptional == false)
//{
// throw;
//}
//trondr: Rethrow the exception
throw new ComponentActivatorException("Failed to resolve property: " + property.Property.Name , ex, Model);
}
}
return null;
}
示例2: ObtainPropertyValue
private object ObtainPropertyValue(CreationContext context, PropertySet property, IDependencyResolver resolver)
{
if (property.Dependency.IsOptional == false ||
resolver.CanResolve(context, context.Handler, Model, property.Dependency))
{
try
{
return resolver.Resolve(context, context.Handler, Model, property.Dependency);
}
catch (Exception)
{
if (property.Dependency.IsOptional == false)
{
throw;
}
}
}
return null;
}
示例3: ObtainPropertyValue
private object ObtainPropertyValue(CreationContext context, PropertySet property, IDependencyResolver resolver)
{
using (new DependencyTrackingScope(context, Model, property.Property, property.Dependency))
{
if (property.Dependency.IsOptional == false ||
resolver.CanResolve(context, context.Handler, Model, property.Dependency))
{
return ObtainPropertyValueCore(context, property, resolver);
}
}
return null;
}
示例4: ObtainPropertyValue
private object ObtainPropertyValue(CreationContext context, PropertySet property, IDependencyResolver resolver)
{
if (property.Dependency.IsOptional == false ||
resolver.CanResolve(context, context.Handler, Model, property.Dependency))
{
try
{
return resolver.Resolve(context, context.Handler, Model, property.Dependency);
}
catch (Exception e)
{
if (property.Dependency.IsOptional == false)
{
throw;
}
Kernel.Logger.Warn(string.Format("Exception when resolving optional dependency {0} on component {1}.", property.Dependency, Model.Name), e);
}
}
return null;
}