src/Autofac/Core/Lifetime/LifetimeScope.cs
/// <summary>
/// Creates and setup the registry for a child scope.
/// </summary>
/// <param name="tag">The tag applied to the <see cref="ILifetimeScope"/>.</param>
/// <param name="configurationAction">Action on a <see cref="ContainerBuilder"/>
/// that adds component registrations visible only in the child scope.</param>
/// <returns>Registry to use for a child scope.</returns>
/// <remarks>It is the responsibility of the caller to make sure that the registry is properly
/// disposed of. This is generally done by adding the registry to the <see cref="Disposer"/>
/// property of the child scope.</remarks>
Creates and setup the registry for a child scope.
Creates and setup the registry for a child scope .
private IComponentRegistryBuilder CreateScopeRestrictedRegistry(object tag, Action<ContainerBuilder> configurationAction)
        {
            var restrictedRootScopeLifetime = new MatchingScopeLifetime(tag);
            var tracker = new ScopeRestrictedRegisteredServicesTracker(restrictedRootScopeLifetime);
            var fallbackProperties = new FallbackDictionary<string, object?>(ComponentRegistry.Properties);
            var registryBuilder = new ComponentRegistryBuilder(tracker, fallbackProperties);
            var builder = new ContainerBuilder(fallbackProperties, registryBuilder);
            foreach (var source in ComponentRegistry.Sources)
            {
                if (source.IsAdapterForIndividualComponents)
                    builder.RegisterSource(source);
            }
            ISharingLifetimeScope? parent = this;
            while (parent != null)
            {
                if (parent.ComponentRegistry.HasLocalComponents)
                {
                    var externalSource = new ExternalRegistrySource(parent.ComponentRegistry);
                    builder.RegisterSource(externalSource);
                    break;
                }
                parent = parent.ParentLifetimeScope;
            }
            configurationAction(builder);
            builder.UpdateRegistry(registryBuilder);
            return registryBuilder;
        }
private IComponentRegistryBuilder CreateScopeRestrictedRegistry ( object tag , Action < ContainerBuilder > configurationAction ) { var restrictedRootScopeLifetime = new MatchingScopeLifetime ( tag ) ; var tracker = new ScopeRestrictedRegisteredServicesTracker ( restrictedRootScopeLifetime ) ; var fallbackProperties = new FallbackDictionary < string , object ? > ( ComponentRegistry . Properties ) ; var registryBuilder = new ComponentRegistryBuilder ( tracker , fallbackProperties ) ; var builder = new ContainerBuilder ( fallbackProperties , registryBuilder ) ; foreach ( var source in ComponentRegistry . Sources ) { if ( source . IsAdapterForIndividualComponents ) builder . RegisterSource ( source ) ; } ISharingLifetimeScope ? parent = this ; while ( parent != null ) { if ( parent . ComponentRegistry . HasLocalComponents ) { var externalSource = new ExternalRegistrySource ( parent . ComponentRegistry ) ; builder . RegisterSource ( externalSource ) ; break ; } parent = parent . ParentLifetimeScope ; } configurationAction ( builder ) ; builder . UpdateRegistry ( registryBuilder ) ; return registryBuilder ; }
Creates and setup the registry for a child scope.
Creates and setup the registry for a child scope .
// Issue #272: Only the most nested parent registry with HasLocalComponents is registered as an external source // It provides all non-adapting registrations from itself and from it's parent registries
Registry to use for a child scope.
Registry to use for a child scope .
tag
object
The tag applied to the .
The tag applied to the .
configurationAction
Action<ContainerBuilder>
Action on a
that adds component registrations visible only in the child scope.
Action on a that adds component registrations visible only in the child scope .
remarks
It is the responsibility of the caller to make sure that the registry is properly
disposed of. This is generally done by adding the registry to the
property of the child scope.
It is the responsibility of the caller to make sure that the registry is properly disposed of . This is generally done by adding the registry to the property of the child scope .