private static ScopeManager CreateManager(Container container, object key) { var threadLocal = new ThreadLocal <Scope>(); var manager = new ScopeManager(container, () => threadLocal.Value, s => threadLocal.Value = s); container.ContainerScope.RegisterForDisposal(threadLocal); return(manager); }
/// <summary> /// Creates a delegate that upon invocation return the current <see cref="Scope"/> for this /// lifestyle and the given <paramref name="container"/>, or null when the delegate is executed outside /// the context of such scope. /// </summary> /// <param name="container">The container for which the delegate gets created.</param> /// <returns>A <see cref="Func{T}"/> delegate. This method never returns null.</returns> protected internal override Func <Scope> CreateCurrentScopeProvider(Container container) { ScopeManager manager = GetScopeManager(container); return(() => manager.CurrentScope); }