/// <summary> /// Create a <see cref="Unity.UnityContainer"/> with the given parent container. /// </summary> /// <param name="parent">The parent <see cref="Unity.UnityContainer"/>. The current object /// will apply its own settings first, and then check the parent for additional ones.</param> private UnityContainer(UnityContainer parent) { // WithLifetime LifetimeContainer = new LifetimeContainer(this); // Context and policies _context = new ContainerContext(this); // Parent _parent = parent ?? throw new ArgumentNullException(nameof(parent)); _parent.LifetimeContainer.Add(this); _root = _parent._root; SetDefaultPolicies = parent.SetDefaultPolicies; // Methods _get = _parent._get; _getGenericRegistration = _parent._getGenericRegistration; _isExplicitlyRegistered = _parent._isExplicitlyRegistered; IsTypeExplicitlyRegistered = _parent.IsTypeExplicitlyRegistered; GetRegistration = (t, n) => _parent.GetRegistration(t, n); Register = CreateAndSetOrUpdate; GetPolicy = parent.GetPolicy; SetPolicy = CreateAndSetPolicy; ClearPolicy = delegate { }; // Strategies _strategies = _parent._strategies; _strategiesChain = _parent._strategiesChain; _strategies.Invalidated += OnStrategiesChanged; // Caches SetDefaultPolicies(this); }