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

CreateBurden() public method

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

			var activator = componentActivator as IDependencyAwareActivator;
			if (activator != null)
			{
				trackedExternally |= activator.IsManagedExternally(resolutionContext.Handler.ComponentModel);
			}

			return resolutionContext.CreateBurden(trackedExternally);
		}

Usage Example

		protected virtual Burden CreateInstance(CreationContext context, bool trackedExternally)
		{
			var burden = context.CreateBurden(ComponentActivator, trackedExternally);

			var instance = componentActivator.Create(context, burden);
			Debug.Assert(ReferenceEquals(instance, burden.Instance));
			return burden;
		}