internal Container([NotNull] string name, [NotNull] IContainer parent) { _name = $"{parent}/{name ?? throw new ArgumentNullException(nameof(name))}"; _parent = parent ?? throw new ArgumentNullException(nameof(parent)); _registrationTracker = new RegistrationTracker(this); // Subscribe to events from the parent container RegisterResource(_parent.Subscribe(_eventSubject)); // Creates a subscription to track infrastructure registrations RegisterResource(_eventSubject.Subscribe(_registrationTracker)); // Register the current container in the parent container _parent.RegisterResource(this); // Notifies about existing registrations in parent containers _eventSubject.OnNext(new ContainerEvent(_parent, EventType.DependencyRegistration, _parent.SelectMany(i => i))); }
internal Container([NotNull] string name, [NotNull] IContainer parent, [NotNull] ILockObject lockObject) { _lockObject = lockObject ?? throw new ArgumentNullException(nameof(parent)); _name = $"{parent}/{name ?? throw new ArgumentNullException(nameof(name))}"; _parent = parent ?? throw new ArgumentNullException(nameof(parent)); _eventSubject = new Subject <ContainerEvent>(_lockObject); _registrationTracker = new RegistrationTracker(this); // Subscribe to events from the parent container RegisterResource(_parent.Subscribe(_eventSubject)); // Creates a subscription to track infrastructure registrations RegisterResource(_eventSubject.Subscribe(_registrationTracker)); // Register the current container in the parent container _parent.RegisterResource(this); // Notifies parent container about the child container creation (_parent as Container)?._eventSubject.OnNext(ContainerEvent.NewContainer(this)); // Notifies about existing registrations in parent containers _eventSubject.OnNext(ContainerEvent.RegisterDependency(_parent, _parent.SelectMany(i => i))); }