Exemple #1
0
        internal ServiceScope CreateChildScope(IServiceScopeFactory rootScopeFactory)
        {
            var       scopedRoot    = rootScopeFactory.CreateScope();
            Container scopedContext = Container.OpenScope() as Container;

            Rules rules = scopedContext.Rules;

            foreach (var unknownServiceResolver in scopedContext.Rules.UnknownServiceResolvers)
            {
                rules = rules.WithoutUnknownServiceResolver(unknownServiceResolver);
            }

            var resolver = scopedContext.With(r => rules.WithUnknownServiceResolvers(request =>
            {
                return(new DelegateFactory(_ => scopedRoot.ServiceProvider.GetService(request.ServiceType)));
            }));

            var scope = new ServiceScope(resolver, scopedRoot);

            ChildScopes.Add(scope);

            scope.DisposalTask.ContinueWith(t => ChildScopes.Remove(scope));

            return(scope);
        }
        private void InitializeScope(JsonToken token, int scopeIndex, JSchema schema, ConditionalContext context)
        {
            // cache this for performance
            int scopeCurrentIndex = scopeIndex;

            // check to see whether a scope with the same schema exists
            SchemaScope childScope = GetExistingSchemaScope(schema, ref scopeCurrentIndex);

            if (childScope == null)
            {
                childScope = SchemaScope.CreateTokenScope(token, schema, context, null, InitialDepth);
            }

#if DEBUG
            childScope.ConditionalParents.Add(this);
#endif

            ChildScopes.Add(childScope);
        }