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


C# CreationContext.EnterResolutionContext方法代码示例

本文整理汇总了C#中Castle.MicroKernel.Context.CreationContext.EnterResolutionContext方法的典型用法代码示例。如果您正苦于以下问题:C# CreationContext.EnterResolutionContext方法的具体用法?C# CreationContext.EnterResolutionContext怎么用?C# CreationContext.EnterResolutionContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Castle.MicroKernel.Context.CreationContext的用法示例。


在下文中一共展示了CreationContext.EnterResolutionContext方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolveCore

		protected override object ResolveCore(CreationContext context, bool track, bool instanceRequired)
		{
			Type implType;
			try
			{
				implType = ComponentModel.Implementation.MakeGenericType(context.GenericArguments);
			}
			catch (ArgumentException)
			{
				// may throw in some cases when impl has generic constraints that service hasn't
				if(instanceRequired)
				{
					throw;
				}
				return null;
			}

			var handler = GetSubHandler(context, implType);

			// so the generic version wouldn't be considered as well
			using(context.EnterResolutionContext(this, false))
			{
				return handler.Resolve(context);
			}
		}
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:25,代码来源:DefaultGenericHandler.cs

示例2: ResolveCore

		protected override object ResolveCore(CreationContext context, bool track, bool instanceRequired)
		{
			Type implType = ComponentModel.Implementation.MakeGenericType(context.GenericArguments);

			IHandler handler = GetSubHandler(context, implType);

			// so the generic version wouldn't be considered as well
			using(context.EnterResolutionContext(this, false))
			{
				return handler.Resolve(context);
			}
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:12,代码来源:DefaultGenericHandler.cs

示例3: ResolveCore

		/// <summary>
		/// Returns an instance of the component this handler
		/// is responsible for
		/// </summary>
		/// <param name="context"></param>
		/// <param name="requiresDecommission"></param>
		/// <param name="instanceRequired"></param>
		/// <returns></returns>
		protected override object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired)
		{
			if (CanResolvePendingDependencies(context) == false)
			{
				if (instanceRequired == false)
				{
					return null;
				}

				AssertNotWaitingForDependency();
			}
			using (var resolutionContext = context.EnterResolutionContext(this,HasDecomission(requiresDecommission)))
			{
				var instance = lifestyleManager.Resolve(context, resolutionContext.Burden, context.ReleasePolicy);
				return instance;
			}
		}
开发者ID:firegrass,项目名称:Castle.Windsor,代码行数:25,代码来源:DefaultHandler.cs

示例4: ResolveCore

		/// <summary>
		/// Returns an instance of the component this handler
		/// is responsible for
		/// </summary>
		/// <param name="context"></param>
		/// <param name="requiresDecommission"></param>
		/// <param name="instanceRequired"></param>
		/// <returns></returns>
		protected override object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired)
		{
			if (ResolveImpossible(context))
			{
				if (instanceRequired == false)
				{
					return null;
				}

				AssertNotWaitingForDependency();
			}
			using (var resolutionContext = context.EnterResolutionContext(this))
			{
				var instance = lifestyleManager.Resolve(context);

				resolutionContext.Burden.SetRootInstance(instance, this, HasDecomission(requiresDecommission));
				context.ReleasePolicy.Track(instance, resolutionContext.Burden);

				return instance;
			}
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:29,代码来源:DefaultHandler.cs

示例5: Resolve

		protected override object Resolve(CreationContext context, bool instanceRequired)
		{
			var implType = GetClosedImplementationType(context, instanceRequired);
			if (implType == null)
			{
				Debug.Assert(instanceRequired == false, "instanceRequired == false");
				return null;
			}

			var handler = GetSubHandler(context, implType);
			// so the generic version wouldn't be considered as well
			using (context.EnterResolutionContext(this, false, false))
			{
				try
				{
					return handler.Resolve(context);
				}
				catch (GenericHandlerTypeMismatchException e)
				{
					throw new HandlerException(
						string.Format(
							"Generic component {0} has some generic dependencies which were not successfully closed. This often happens when generic implementation has some additional generic constraints. See inner exception for more details.",
							ComponentModel.Name), ComponentModel.ComponentName, e);
				}
			}
		}
开发者ID:rtr0mdrn,项目名称:Windsor,代码行数:26,代码来源:DefaultGenericHandler.cs

示例6: Resolve

		protected override object Resolve(CreationContext context, bool instanceRequired)
		{
			var implType = GetClosedImplementationType(context, instanceRequired);
			if (implType == null)
			{
				Debug.Assert(instanceRequired == false, "instanceRequired == false");
				return null;
			}

			var handler = GetSubHandler(context, implType);
			// so the generic version wouldn't be considered as well
			using (context.EnterResolutionContext(this, false, false))
			{
				return handler.Resolve(context);
			}
		}
开发者ID:n2cms,项目名称:Castle.Windsor,代码行数:16,代码来源:DefaultGenericHandler.cs

示例7: ResolveCore

		/// <summary>
		///   Returns an instance of the component this handler
		///   is responsible for
		/// </summary>
		/// <param name = "context"> </param>
		/// <param name = "requiresDecommission"> </param>
		/// <param name = "instanceRequired"> </param>
		/// <param name = "burden"> </param>
		/// <returns> </returns>
		protected object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired, out Burden burden)
		{
			if (IsBeingResolvedInContext(context))
			{
				var cache = lifestyleManager as IContextLifestyleManager;
				if (cache != null)
				{
					var instance = cache.GetContextInstance(context);
					if (instance != null)
					{
						burden = null;
						return instance;
					}
				}

				if (instanceRequired == false)
				{
					burden = null;
					return null;
				}
				var message = new StringBuilder();
				message.AppendFormat("Dependency cycle has been detected when trying to resolve component '{0}'.",
				                     ComponentModel.Name);
				message.AppendLine();
				message.AppendLine("The resolution tree that resulted in the cycle is the following:");
				context.BuildCycleMessageFor(this, message);

				throw new CircularDependencyException(message.ToString(), ComponentModel);
			}
			if (CanResolvePendingDependencies(context) == false)
			{
				if (instanceRequired == false)
				{
					burden = null;
					return null;
				}

				AssertNotWaitingForDependency();
			}
			try
			{
				using (var ctx = context.EnterResolutionContext(this, requiresDecommission))
				{
					var instance = lifestyleManager.Resolve(context, context.ReleasePolicy);
					burden = ctx.Burden;
					return instance;
				}
			}
			catch (NoResolvableConstructorFoundException)
			{
				throw UnresolvableHandlerException();
			}
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:62,代码来源:DefaultHandler.cs

示例8: ResolveCore

		/// <summary>
		///   Returns an instance of the component this handler
		///   is responsible for
		/// </summary>
		/// <param name = "context"></param>
		/// <param name = "requiresDecommission"></param>
		/// <param name = "instanceRequired"></param>
		/// <param name = "burden"></param>
		/// <returns></returns>
		protected object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired, out Burden burden)
		{
			if (CanResolvePendingDependencies(context) == false)
			{
				if (instanceRequired == false)
				{
					burden = null;
					return null;
				}

				AssertNotWaitingForDependency();
			}
			using (var ctx = context.EnterResolutionContext(this, requiresDecommission))
			{
				var instance = lifestyleManager.Resolve(context, context.ReleasePolicy);
				burden = ctx.Burden;
				return instance;
			}
		}
开发者ID:martinernst,项目名称:Castle.Windsor,代码行数:28,代码来源:DefaultHandler.cs

示例9: ResolveCore

		protected override object ResolveCore(CreationContext context, bool requiresDecommission, bool instanceRequired)
		{
			Type implType;
			try
			{
				// TODO: what if ComponentModel.Implementation is a LateBoundComponent?
				implType = ComponentModel.Implementation.MakeGenericType(context.GenericArguments);
			}
			catch (ArgumentException e)
			{
				// may throw in some cases when impl has generic constraints that service hasn't
				if (instanceRequired == false)
				{
					return null;
				}

				// ok, let's do some investigation now what might have been the cause of the error
				var arguments = ComponentModel.Implementation.GetGenericArguments();
				if (arguments.Length > context.GenericArguments.Length)
				{
					var message =
						string.Format(
							"Requested type {0} has {1} generic parameter(s), whereas component implementation type {2} requires {3}. This means that Windsor does not have enough information to properly create that component for you. This is most likely a bug in your registration code.",
							context.RequestedType, context.GenericArguments.Length, ComponentModel.Implementation, arguments.Length);
					throw new HandlerException(message, e);
				}
				// we have correct number of generic arguments, that means probably some generic constraing was violated.
				// the CLR exception should suffice
				throw;
			}

			var handler = GetSubHandler(context, implType);

			// so the generic version wouldn't be considered as well
			using (context.EnterResolutionContext(this, false))
			{
				return handler.Resolve(context);
			}
		}
开发者ID:7digital,项目名称:Castle.Windsor,代码行数:39,代码来源:DefaultGenericHandler.cs


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