本文整理汇总了C#中Castle.Core.DependencyModel类的典型用法代码示例。如果您正苦于以下问题:C# DependencyModel类的具体用法?C# DependencyModel怎么用?C# DependencyModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DependencyModel类属于Castle.Core命名空间,在下文中一共展示了DependencyModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: Resolve
public object Resolve(CreationContext context,
ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
return _kernel.ResolveAll(dependency.TargetType.GetElementType(), null);
}
示例3: 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);
}
示例4: Inspect
public void Inspect(IHandler handler, DependencyModel[] missingDependencies, IKernel kernel)
{
if (handlersChecked.Add(handler) == false)
{
return;
}
Debug.Assert(missingDependencies.Length > 0, "missingDependencies.Length > 0");
var uniqueOverrides = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
message.AppendLine();
message.AppendFormat("'{0}' is waiting for the following dependencies:", handler.ComponentModel.Name);
message.AppendLine();
foreach (var dependency in missingDependencies)
{
if (dependency.ReferencedComponentName != null)
{
// NOTE: that's a workaround for us having dependency twice potentially, once from configuration and once from actual type scan
if (uniqueOverrides.Add(dependency.ReferencedComponentName))
{
InspectServiceOverrideDependency(dependency, kernel);
}
}
else if (dependency.IsPrimitiveTypeDependency)
{
//hardcoding string as it's a most common type that is not value type but you wouldn't want to kave that as a service.
InspectParameterDependency(dependency);
}
else
{
InspectServiceDependency(handler, dependency, kernel);
}
}
}
示例5: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
DependencyModel dependency)
{
if (dependency.TargetType == typeof (ISession))
return SessionFactory.OpenSession();
return SessionFactory.OpenStatelessSession();
}
示例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: TrackDependency
private DependencyModelExtended TrackDependency(ComponentModel model, MemberInfo info, DependencyModel dependencyModel)
{
DependencyModelExtended trackingKey = new DependencyModelExtended(model, dependencyModel, info);
if (dependencies.Contains(trackingKey))
{
StringBuilder sb = new StringBuilder("A cycle was detected when trying to resolve a dependency. ");
sb.Append("The dependency graph that resulted in a cycle is:");
foreach(DependencyModel key in dependencies)
{
DependencyModelExtended extendedInfo = key as DependencyModelExtended;
if (extendedInfo != null)
{
sb.AppendFormat("\r\n - {0} for {1} in type {2}",
key, extendedInfo.Info, extendedInfo.Info.DeclaringType);
}
else
{
sb.AppendFormat("\r\n - {0}", key);
}
}
sb.AppendFormat("\r\n + {0} for {1} in {2}\r\n",
dependencyModel, info, info.DeclaringType);
throw new CircularDependencyException(sb.ToString());
}
dependencies.Add(trackingKey);
return trackingKey;
}
示例8: CanResolve
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
DependencyModel dependency)
{
return Context.CurrentUser != null &&
dependency.TargetType == typeof (INotifications);
}
示例9: Inspect
public void Inspect(IHandler handler, DependencyModel[] missingDependencies, IKernel kernel)
{
if (handlersChecked.Add(handler) == false)
{
return;
}
Debug.Assert(missingDependencies.Length > 0, "missingDependencies.Length > 0");
message.AppendLine();
message.AppendFormat("'{0}' is waiting for the following dependencies:", handler.ComponentModel.Name);
message.AppendLine();
foreach (var dependency in missingDependencies)
{
switch (dependency.DependencyType)
{
case DependencyType.Service:
InspectServiceDependency(handler, dependency, kernel);
break;
case DependencyType.ServiceOverride:
InspectServiceOverrideDependency(dependency, kernel);
break;
case DependencyType.Parameter:
InspectParameterDependency(dependency);
break;
}
}
}
示例10: 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));
}
示例11: 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);
}
示例12: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
Type t = dependency.TargetType.GetGenericArguments()[0];
return kernel.ResolveAll(t, null);
}
示例13: 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;
}
示例14: 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;
}
示例15: CreateConstructorCandidate
protected virtual ConstructorCandidate CreateConstructorCandidate(ConstructorInfo constructor)
{
ParameterInfo[] parameters = constructor.GetParameters();
DependencyModel[] dependencies = new DependencyModel[parameters.Length];
for(int i = 0; i < parameters.Length; i++)
{
ParameterInfo parameter = parameters[i];
Type paramType = parameter.ParameterType;
// This approach is somewhat problematic. We should use
// another strategy to differentiate types and classify dependencies
if (converter.IsSupportedAndPrimitiveType(paramType))
{
dependencies[i] = new DependencyModel(
DependencyType.Parameter, parameter.Name, paramType, false);
}
else
{
dependencies[i] = new DependencyModel(
DependencyType.Service, parameter.Name, paramType, false);
}
}
return new ConstructorCandidate(constructor, dependencies);
}