本文整理汇总了C#中ISubDependencyResolver类的典型用法代码示例。如果您正苦于以下问题:C# ISubDependencyResolver类的具体用法?C# ISubDependencyResolver怎么用?C# ISubDependencyResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISubDependencyResolver类属于命名空间,在下文中一共展示了ISubDependencyResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 (CanResolveFromContext(context, contextHandlerResolver, model, dependency))
{
return true;
}
// 2 - check with the model's handler, if not the same as the parent resolver
if (CanResolveFromHandler(context, contextHandlerResolver, model, dependency))
{
return true;
}
// 3 - check within parent resolver, if present
if (CanResolveFromContextHandlerResolver(context, contextHandlerResolver, model, dependency))
{
return true;
}
// 4 - check within subresolvers
if (CanResolveFromSubResolvers(context, contextHandlerResolver, model, dependency))
{
return true;
}
// 5 - normal flow, checking against the kernel
return CanResolveFromKernel(context, model, dependency);
}
示例2: Resolve
public object Resolve(
CreationContext context,
ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
MockingStrategy strategy = _relatedRepository.GetStrategyFor(dependency);
if (strategy.Instance != null)
return strategy.Instance;
if (strategy.Mock == MockingStrategyType.Mock)
{
//if a dependencywas already registered in the main controller, go and use it
var registration = this._relatedRepository.Kernel.GetHandler(dependency.TargetType);
object resolvedDependencyObject;
if (registration == null)
{
resolvedDependencyObject = MockRepository.GenerateStub(dependency.TargetType);
}
else
{
resolvedDependencyObject = _relatedRepository.Resolve(dependency.TargetType);
}
_relatedRepository.OnMockCreated(resolvedDependencyObject, dependency.DependencyKey);
return resolvedDependencyObject;
}
if (strategy.Mock == MockingStrategyType.Resolve)
return _relatedRepository.Resolve(dependency.TargetType);
return null;
}
示例3: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
DependencyModel dependency)
{
if (dependency.TargetType == typeof (ISession))
return SessionFactory.OpenSession();
return SessionFactory.OpenStatelessSession();
}
示例4: CanResolve
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
{
return dependency.TargetType != null &&
dependency.TargetType.IsArray &&
dependency.TargetType.GetElementType().IsInterface &&
!model.Parameters.Contains(dependency.DependencyKey);
}
示例5: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
{
string componentName = null;
if (!_knownDependencies.ContainsKey(dependency))
componentName = dependency.DependencyKey;
return _kernel.Resolve(componentName, dependency.TargetType);
}
示例6: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
DependencyModel dependency)
{
return contextHandlerResolver.Resolve(context, contextHandlerResolver, model,
new DependencyModel(DependencyType.Service, typeof(IBookStore).FullName,
typeof(IBookStore), false));
}
示例7: CanResolve
/// <inheritdoc />
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, DependencyModel dependency)
{
if (dependency.TargetType == null)
{
return false;
}
Type genericArgument = null;
if ((dependency.TargetType.IsGenericType) && (dependency.TargetType.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
{
genericArgument = dependency.TargetType.GetGenericArguments()[0];
}
else
{
dependency.TargetType.GetInterfaces().Any(implemented => (implemented.IsGenericType) && (implemented.GetGenericTypeDefinition() == typeof(IEnumerable<>)) &&
((genericArgument = implemented.GetGenericArguments()[0]) != null));
}
if ((genericArgument == null) || (!_kernel.HasComponent(genericArgument)))
{
return false;
}
return true;
}
示例8: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
Type t = dependency.TargetType.GetGenericArguments()[0];
return kernel.ResolveAll(t, null);
}
示例9: 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));
}
示例10: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
DependencyModel dependency)
{
Type elementType = dependency.TargetType.GetElementType();
Array all = kernel.ResolveAll(elementType, new Hashtable());
return all;
}
示例11: Resolve
public object Resolve(CreationContext context,
ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
return _kernel.ResolveAll(dependency.TargetType.GetElementType(), null);
}
示例12: CanResolve
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
DependencyModel dependency)
{
return Context.CurrentUser != null &&
dependency.TargetType == typeof (INotifications);
}
示例13: CanResolve
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
return dependency.TargetType != null &&
dependency.TargetType.IsArray &&
dependency.TargetType.GetElementType().IsInterface;
}
示例14: Resolve
public override object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver,
ComponentModel model,
DependencyModel dependency)
{
var items = base.Resolve(context, contextHandlerResolver, model, dependency);
var listType = BuildListType(dependency);
return listType.CreateInstance<object>(items);
}
示例15: CanResolve
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver,
ComponentModel model,
DependencyModel dependency)
{
return dependency.TargetType != null &&
dependency.TargetType.IsArray &&
kernel.HasComponent(dependency.TargetType.GetElementType());
}