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


C# IContext.PrepareForActivation方法代码示例

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


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

示例1: DoInject

		/*----------------------------------------------------------------------------------------*/
		/// <summary>
		/// Injects an existing instance of a service.
		/// </summary>
		/// <param name="instance">The existing instance to inject.</param>
		/// <param name="context">The context in which the instance should be injected.</param>
		protected override void DoInject(object instance, IContext context)
		{
			Type service = instance.GetType();

			context.Instance = instance;

			if (context.Binding == null)
				context.PrepareForActivation(ResolveBinding(service, context));

			Components.Activator.Activate(context);

			if (context.ShouldTrackInstance)
				context.Scope.Register(context);
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:20,代码来源:KernelBase.cs

示例2: DoResolve

		/*----------------------------------------------------------------------------------------*/
		#region Protected Methods: Instances
		/// <summary>
		/// Resolves an instance of a bound type.
		/// </summary>
		/// <param name="service">The type of instance to resolve.</param>
		/// <param name="context">The context in which the instance should be resolved.</param>
		/// <returns>The resolved instance.</returns>
		protected override object DoResolve(Type service, IContext context)
		{
			if (context.Binding == null)
			{
				IBinding binding = ResolveBinding(service, context);

				if (binding == null)
				{
					if (context.IsOptional)
					{
						if (Logger.IsDebugEnabled)
							Logger.Debug("No bindings were found for the service {0}, ignoring since the request was optional", Format.Type(service));

						return null;
					}
					else
					{
						// We couldn't resolve a binding for the service, so fail.
						throw new ActivationException(ExceptionFormatter.CouldNotResolveBindingForType(service, context));
					}
				}

				context.PrepareForActivation(binding);
			}

			if (Logger.IsDebugEnabled)
				Logger.Debug("Resolving instance for {0}{1}", Format.Context(context), (context.IsEagerActivation ? " (eager activation)" : ""));

			if (context.IsEagerActivation && !context.Plan.Behavior.SupportsEagerActivation)
			{
				if (Logger.IsDebugEnabled)
					Logger.Debug("This is an eager activation request and the plan's behavior does not support it. Not actually activating an instance.");

				return null;
			}

			if (context.Instance == null)
				context.Instance = context.Plan.Behavior.Resolve(context);

			if (context.ShouldTrackInstance)
				context.Scope.Register(context);

			return context.Instance;
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:52,代码来源:KernelBase.cs


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