Ejemplo n.º 1
0
        /// <summary>
        /// Deactivates the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="reference">The reference.</param>
        public override void Deactivate(IContext context, InstanceReference reference)
        {
            var messageBroker = context.Kernel.Components.Get <IMessageBroker>();

            IEnumerable <PublicationDirective> publications = context.Plan.GetAll <PublicationDirective>();

            foreach (PublicationDirective publication in publications)
            {
                IMessageChannel channel = messageBroker.GetChannel(publication.Channel);
                channel.RemovePublication(reference.Instance, publication.Event);
            }

            IEnumerable <SubscriptionDirective> subscriptions = context.Plan.GetAll <SubscriptionDirective>();

            foreach (SubscriptionDirective subscription in subscriptions)
            {
                IMessageChannel channel = messageBroker.GetChannel(subscription.Channel);
                channel.RemoveSubscription(reference.Instance, subscription.Injector);
            }
        }
Ejemplo n.º 2
0
        /*----------------------------------------------------------------------------------------*/
        /// <summary>
        /// Executed before the instance is destroyed.
        /// </summary>
        /// <param name="context">The activation context.</param>
        /// <returns>A value indicating whether to proceed or stop the execution of the strategy chain.</returns>
        public override StrategyResult BeforeDestroy(IContext context)
        {
            var messageBroker = context.Binding.Components.Get <IMessageBroker>();

            IList <PublicationDirective> publications = context.Plan.Directives.GetAll <PublicationDirective>();

            foreach (PublicationDirective publication in publications)
            {
                IMessageChannel channel = messageBroker.GetChannel(publication.Channel);
                channel.RemovePublication(context.Instance, publication.Event);
            }

            IList <SubscriptionDirective> subscriptions = context.Plan.Directives.GetAll <SubscriptionDirective>();

            foreach (SubscriptionDirective subscription in subscriptions)
            {
                IMessageChannel channel = messageBroker.GetChannel(subscription.Channel);
                channel.RemoveSubscription(context.Instance, subscription.Injector);
            }

            return(StrategyResult.Proceed);
        }