Castle.MicroKernel.Context.CreationContext.AttachExistingBurden C# (CSharp) Method

AttachExistingBurden() public method

public AttachExistingBurden ( Burden burden ) : void
burden Burden
return void
		public void AttachExistingBurden(Burden burden)
		{
			ResolutionContext resolutionContext;
			try
			{
				resolutionContext = resolutionStack.Peek();
			}
			catch (InvalidOperationException)
			{
				throw new ComponentActivatorException(
					"Not in a resolution context. 'AttachExistingBurden' method can only be called withing a resoltion scope. (after 'EnterResolutionContext' was called within a handler)",
					null);
			}
			resolutionContext.AttachBurden(burden);
		}

Usage Example

Exemplo n.º 1
0
		public virtual object Request(CreationContext context, Func<CreationContext, Burden> creationCallback)
		{
			using (rwlock.ForWriting())
			{
				if (!initialized)
				{
					Intitialize(creationCallback, context);
				}

				Burden burden;
				if (available.Count != 0)
				{
					burden = available.Pop();
					context.AttachExistingBurden(burden);
				}
				else
				{
					burden = creationCallback.Invoke(context);
				}
				try
				{
					inUse.Add(burden.Instance, burden);
				}
				catch (NullReferenceException)
				{
					throw new PoolException("creationCallback didn't return a valid burden");
				}
				catch (ArgumentNullException)
				{
					throw new PoolException("burden returned by creationCallback does not have root instance associated with it (its Instance property is null).");
				}
				return burden.Instance;
			}
		}