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

SelectScopeRoot() public method

public SelectScopeRoot ( IHandler>.Func scopeRootSelector ) : ResolutionContext
scopeRootSelector IHandler>.Func
return ResolutionContext
		public ResolutionContext SelectScopeRoot(Func<IHandler[], IHandler> scopeRootSelector)
		{
			var scopes = resolutionStack.Select(c => c.Handler).Reverse().ToArray();
			var selected = scopeRootSelector(scopes);
			if (selected != null)
			{
				var resolutionContext = resolutionStack.SingleOrDefault(s => s.Handler == selected);
				if (resolutionContext != null)
				{
					return resolutionContext;
				}
			}
			return null;
		}

Usage Example

		private IScopeCache GetScopeImplicit(bool required, CreationContext context)
		{
			var selected = context.SelectScopeRoot(selector);
			if (selected == null && required)
			{
				throw new InvalidOperationException(string.Format("Scope was not available for '{0}'. Did you forget to call container.BeginScope()?", componentModel.Name));
			}
			return GetCache(selected);
		}