Ejemplo n.º 1
0
 public void BeginInvoke(Action action)
 {
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     _applicationEventQueue.Enqueue(new ActionEvent(action));
 }
        public void Handle(ItemCompletedEvent <InstanceLookup> applicationEvent)
        {
            if (applicationEvent.Item.SharedInstanceReused)
            {
                return;
            }

            var lifetime = applicationEvent.Item.ActivationScope;

            if (!lifetime.IsRootScope)
            {
                return;
            }

            var component = applicationEvent.Item.Component;

            if (component.IsTracked)
            {
                if (_warnedComponents.Contains(component))
                {
                    return;
                }

                var message      = string.Format("The disposable component {0} was activated in the root scope. This means the instance will be kept alive for the lifetime of the container.", component.Description);
                var messageEvent = new MessageEvent(MessageRelevance.Warning, "Tracked Component in Root Scope", message);
                _applicationEventQueue.Enqueue(messageEvent);
            }
        }
Ejemplo n.º 3
0
        public void Handle(ClockTickEvent applicationEvent)
        {
            var keysToRemove = new List <LifetimeScope>();

            var earliestAllowableCreationTime = DateTime.Now - AgeThreshold;

            foreach (var activeScope in _activeScopes)
            {
                var lifetimeScope = activeScope.Key;
                var createdAt     = activeScope.Value;

                if (createdAt < earliestAllowableCreationTime)
                {
                    if (!_descriptionsOfScopesWarnedAbout.Contains(lifetimeScope.Description))
                    {
                        _descriptionsOfScopesWarnedAbout.Add(lifetimeScope.Description);
                        var message      = string.Format("A {0} lifetime scope has been active for more than {1} seconds. To ensure that components are properly released, lifetime scopes must be disposed when no longer required.", lifetimeScope.Description, AgeThreshold.TotalSeconds);
                        var messageEvent = new MessageEvent(MessageRelevance.Warning, "Lifetime Scope not Disposed", message);
                        _applicationEventQueue.Enqueue(messageEvent);
                    }

                    keysToRemove.Add(lifetimeScope);
                }
            }

            foreach (var removed in keysToRemove)
            {
                _activeScopes.Remove(removed);
            }
        }
        public void Handle(ItemCompletedEvent <LifetimeScope> applicationEvent)
        {
            var lifetimeScope = applicationEvent.Item;
            var messageEvent  = new MessageEvent(MessageRelevance.Information, "Lifetime scope disposed", lifetimeScope.Description);

            _applicationEventQueue.Enqueue(messageEvent);
        }
Ejemplo n.º 5
0
 public void UpdateFrom(ProfilerConnectedMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     _applicationEventQueue.Enqueue(new ProfilerConnectedEvent(message.ProcessName, message.ProcessId));
 }
Ejemplo n.º 6
0
        public void Handle(ItemCompletedEvent <ResolveOperation> applicationEvent)
        {
            if (applicationEvent == null)
            {
                throw new ArgumentNullException("applicationEvent");
            }

            var instanceLookup = applicationEvent.Item.RootInstanceLookup;

            if (instanceLookup.SharedInstanceReused)
            {
                return;
            }

            var activationScope = instanceLookup.ActivationScope;

            if (!activationScope.IsRootScope)
            {
                return;
            }

            var component = instanceLookup.Component;

            if (component.LimitType.Identity.FullName == OwnedTypeFullName)
            {
                return;
            }

            LastNActivationsScopeTracker tracker;

            if (!_componentToScopeTrackers.TryGetValue(component.Id, out tracker))
            {
                tracker = new LastNActivationsScopeTracker(MaxActivationScopesToTrackPerComponent);
                _componentToScopeTrackers[component.Id] = tracker;
            }

            if (tracker.HasWarningBeenIssued)
            {
                return;
            }

            var resolveOperationsInThisScope = tracker.RecordActivation(activationScope.Id);

            if (resolveOperationsInThisScope == ResolveOperationsBeforeWarning)
            {
                var message = string.Format("The component {0} has been resolved twice directly from the container. This can indicate a potential memory leak.", component.Description);
                var warning = new MessageEvent(MessageRelevance.Warning, "Possible Memory Leak", message);
                _applicationEventQueue.Enqueue(warning);
                tracker.HasWarningBeenIssued = true;
            }
        }
Ejemplo n.º 7
0
        public void Handle(ItemCompletedEvent <LifetimeScope> applicationEvent)
        {
            var lifetimeScope = applicationEvent.Item;

            if (lifetimeScope.ActiveChildren.Count != 0)
            {
                if (_descriptionsOfParentsWithWarningsIssued.Contains(lifetimeScope.Description))
                {
                    return;
                }

                _descriptionsOfParentsWithWarningsIssued.Add(lifetimeScope.Description);
                var children     = string.Join(", ", lifetimeScope.ActiveChildren.Select(ls => ls.Description));
                var message      = string.Format("A {0} lifetime scope was disposed before its active children (including {1}).", lifetimeScope.Description, children);
                var messageEvent = new MessageEvent(MessageRelevance.Error, "Out-of-Order Disposal", message);
                _applicationEventQueue.Enqueue(messageEvent);
            }
        }
Ejemplo n.º 8
0
 public void Add(TItem item)
 {
     _items.Add(item.Id, item);
     _applicationEventQueue.Enqueue(new ItemCreatedEvent <TItem>(item));
 }