当前位置: 首页>>代码示例>>C#>>正文


C# CreationContext.HandlerIsCurrentlyBeingResolved方法代码示例

本文整理汇总了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;
		}
开发者ID:ralescano,项目名称:castle,代码行数:20,代码来源:DefaultHandler.cs

示例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;
		}
开发者ID:ralescano,项目名称:castle,代码行数:12,代码来源:DefaultDependencyResolver.cs

示例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;
		}
开发者ID:ralescano,项目名称:castle,代码行数:22,代码来源:DefaultDependencyResolver.cs

示例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);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:60,代码来源:DefaultDependencyResolver.cs


注:本文中的CreationContext.HandlerIsCurrentlyBeingResolved方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。