public ILifetimeScope GetScope(CreationContext context)
        {
            var selected = context.SelectScopeRoot(scopeRootSelector);

            if (selected == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Scope was not available for '{0}'. No component higher up in the resolution stack met the criteria specified for scoping the component. This usually indicates a bug in custom scope root selector or means that the component is being resolved in a unforseen context (a.k.a - it's probably a bug in how the dependencies in the application are wired).",
                              componentModel.Name));
            }
            var stash = (DefaultLifetimeScope)selected.GetContextualProperty(ScopeStash);

            if (stash == null)
            {
                DefaultLifetimeScope newStash = null;
                newStash = new DefaultLifetimeScope(new ScopeCache(), burden =>
                {
                    if (burden.RequiresDecommission)
                    {
                        selected.Burden.RequiresDecommission = true;
                        selected.Burden.GraphReleased       += delegate { newStash.Dispose(); };
                    }
                });
                selected.SetContextualProperty(ScopeStash, newStash);
                stash = newStash;
            }
            return(stash);
        }
Beispiel #2
0
        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));
        }